Navbar dropdown

Hi there,

I’m working on new project in Sage and I just realized that navbar dropdown is not working at all.

Bootstrap dropdown class is not being added to Worpdress submenu.

Any idea how can I fix it?

Thanks in advance.

The default Sage example code doesn’t use a Bootstrap “navbar” component. You’ll need a Bootstrap navwalker and some additional container code to make a more traditional navbar. I maintain a navwalker example here:

3 Likes

Thanks. Any idea how do I add that to Sage?

With Sage, or any theme for that matter, you need to configure wp_nav_menu to use the nav walker that @MWDelaney provided.

wp_nav_menu( array(
                'menu'              => 'primary',
                'theme_location'    => 'primary',
                'depth'             => 2,
                'container'         => 'div',
                'container_class'   => 'collapse navbar-collapse',
                'container_id'      => 'bs-example-navbar-collapse-1',
                'menu_class'        => 'nav navbar-nav',
                'fallback_cb'       => 'wp_bootstrap4_navwalker::fallback',
                'walker'            => new wp_bootstrap4_navwalker())
            ); 

This is all documented in the WordPress Codex, btw. See wp_nav_menu() function documentation

2 Likes

Thanks very much. That’s helpful.

I bet I do that somewhere in setup.php?

You register your menus in setup.php. Use wp_nav_menu() with the $args in your Blade template. Again, this is all documented in that link I provided.

1 Like

Thanks a lot. That’s helpful. I also find this video here so I know I have to add navwalker.