theme_location == $menu_location) {
$items .= '';
$items .= '';
$items .= '';
}
return $items;
}
}
if (!function_exists('ct_page_menu')) {
function ct_page_menu($args = array())
{
$defaults = array(
'sort_column' => 'menu_order, post_title',
'menu_id' => '',
'menu_class' => 'menu',
'container' => 'div',
'echo' => true,
'link_before' => '',
'link_after' => '',
'before' => '',
'item_spacing' => 'discard',
'walker' => '',
);
$args = wp_parse_args($args, $defaults);
if (!in_array($args['item_spacing'], array('preserve', 'discard'), true)) {
// Invalid value, fall back to default.
$args['item_spacing'] = $defaults['item_spacing'];
}
if ('preserve' === $args['item_spacing']) {
$t = "\t";
$n = "\n";
} else {
$t = '';
$n = '';
}
/**
* Filters the arguments used to generate a page-based menu.
*
* @since 2.7.0
*
* @see wp_page_menu()
*
* @param array $args An array of page menu arguments. See wp_page_menu()
* for information on accepted arguments.
*/
$args = apply_filters('wp_page_menu_args', $args);
$menu = '';
$list_args = $args;
// Show Home in the menu.
if (!empty($args['show_home'])) {
if (true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home']) {
$text = __('Home', 'blockwp');
} else {
$text = $args['show_home'];
}
$class = '';
if (is_front_page() && !is_paged()) {
$class = 'class="current_page_item"';
}
$menu .= '' . $args['link_before'] . $text . $args['link_after'] . '';
// If the front page is a page, add it to the exclude list.
if ('page' === get_option('show_on_front')) {
if (!empty($list_args['exclude'])) {
$list_args['exclude'] .= ',';
} else {
$list_args['exclude'] = '';
}
$list_args['exclude'] .= get_option('page_on_front');
}
}
$list_args['echo'] = false;
$list_args['title_li'] = '';
$menu .= wp_list_pages($list_args);
$container = sanitize_text_field($args['container']);
// Fallback in case `wp_nav_menu()` was called without a container.
if (empty($container)) {
$container = 'div';
}
$items = "";
if ($menu) {
$items .= '';
$items .= '';
$items .= '';
// wp_nav_menu() doesn't set before and after.
if (
isset($args['fallback_cb']) &&
'wp_page_menu' === $args['fallback_cb'] &&
'ul' !== $container
) {
$args['before'] = "{$n}";
$args['after'] = '
';
}
$menu = $args['before'] . $menu . $items . $args['after'];
}
$attrs = '';
if (!empty($args['menu_id'])) {
$attrs .= ' id="' . esc_attr($args['menu_id']) . '"';
}
if (!empty($args['menu_class'])) {
$attrs .= ' class="' . esc_attr($args['menu_class']) . '"';
}
$menu = "<{$container}{$attrs}>" . $menu . "{$container}>{$n}";
/**
* Filters the HTML output of a page-based menu.
*
* @since 2.7.0
*
* @see wp_page_menu()
*
* @param string $menu The HTML output.
* @param array $args An array of arguments. See wp_page_menu()
* for information on accepted arguments.
*/
$menu = apply_filters('wp_page_menu', $menu, $args);
if ($args['echo']) {
echo $menu;
} else {
return $menu;
}
}
}