0

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.com/wp-bootstrap/wp-bootstrap-navwalker. I am new to wordpress and I hope someone would enlighten me. Thanks

1

Yes, 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.

| improve this answer | |
  • @Kryzsiek , if it is not specified the depth does it mean that it will display all submenus? – Lucifer Levi Nov 22 '19 at 3:37
  • Yes - 0 is the default value for that argument and it means that all levels should be printed. – Krzysiek Dróżdż Nov 22 '19 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.