Support » Fixing WordPress » Problem with wp_nav_menu() – hiding menu container
3 years, 2 months ago
I need to hide the menu container and to change the UL class.
So my options are:
wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘container_class’ => false, ‘container’ => ”, ‘menu_class’ => ‘my-menu’ ) );
This line works only if a primary menu is specified, otherwise the fallback_cb points to wp_page_menu() and ‘container_class’ / ‘container’ are ignored.
It seems a bug to me…
Perhaps you need to register the menu with register_nav_menu.
Nav Menu already registered in my functions.php \ ‘after_setup_theme’ action.
IMO the problem is that “wp_page_menu” function seems to ignore some of the options of “wp_nav_menu” (container, container_class, …).
3 years, 1 month ago
Experiencing the same problem as Mat. Options passed in when calling the menu are not being applied correctly.
I’m calling the menu like so:
<?php wp_nav_menu( array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'list-inline'
) ); ?>
Which results in the following markup:
<ul class=" nav-menu">
The menu class is actually being applied to the wrapper div, which shouldn’t even be there. I’m with Mat on the cause of this, see link in previous post.
Has this been recognised as a bug? Definitely something wonky going on!
Just realised that I was using the default menu. When I created a custom menu, the container and classes were applied correctly.
Give it a try, Mat.
2 years, 8 months ago
Thank you for the tip. If I create a menu it works.
But I think it should also work with the auto generated menu…