In my Wordpress application, wp_nav_menu is not visible. The other menu works as intended.
This is invisible:
<?php wp_nav_menu( array('theme_location' => 'mobile_menu', 'container_class'=>'my-mobile-wrapper')); ?>
This is visible (both are in header.php)
<?php wp_nav_menu( array('theme_location' => 'header_menu', 'container_class'=>'header-menu')); ?>
I read a suggestion from somewhere, but adding this to functions.php didn't work.
add_action( 'pre_get_posts', 'my_pre_get_posts' );
function my_pre_get_posts($query) {
if ($query->get('post_type') === 'nav_menu_item') {
$query->set('tax_query','');
}
}
I register as follows:
if (!function_exists('my_register_menus')) {
function my_register_menus() {
register_nav_menus(
array(
'header_menu' => __('Header Menu', "my"),
'mobile_menu' => __('Mobile Menu', "my")
)
);
}
}
add_action( 'after_setup_theme', 'my_register_menus' );
Thanks by now.
OK I found the answer.
I use a function to extend menu contents and I do a structural mistake at that point. I write here for the ones who might face a similar problem:
add_filter( 'wp_nav_menu_items', 'my_extend_menu_content', 10, 2 );
function my_extend_menu_content($items, $args){
switch .... for menus other than mobile.
// After the switch block:
return false; // which is wrong.
return $items; // should be this way.
}