I want to ask if this <?php wp_nav_menu( array('theme_location' => 'primary') ); ?>
get all the sub-menu automatically? I saw this one of my downloaded theme and it displays all the submenu only using this and css code. I am curious why it display the submenu even though it doesn't uses walker class for example like this
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'navbar-nav mr-auto',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
) );
with another walker file like this . I am new to wordpress and I hope someone would enlighten me. Thanks
I want to ask if this <?php wp_nav_menu( array('theme_location' => 'primary') ); ?>
get all the sub-menu automatically? I saw this one of my downloaded theme and it displays all the submenu only using this and css code. I am curious why it display the submenu even though it doesn't uses walker class for example like this
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'navbar-nav mr-auto',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
) );
with another walker file like this https://github/wp-bootstrap/wp-bootstrap-navwalker
. I am new to wordpress and I hope someone would enlighten me. Thanks
1 Answer
Reset to default 1Yes, wp_nav_menu
displays all levels of menu by default.
You don't have to write your custom walker class to display submenu items - WordPress already has one which is used by default.
WP_Bootstrap_Navwalker
is used only because given theme uses Bootstrap and nav menu should generate custom HTML code, which is compatible with Bootstrap.
The only thing you have to remember is that there is depth
argument which decides how many levels of menu should be printed.