Bootstrap dropdown nav pills not working with wp_nav_menu()

I ran into similar problem when I created a bootstrap navigation menu and dropdown links were all showing up at once.
I used the following steps to correct the issue:

  1. download navwalker from github repo link: https://github.com/wp-bootstrap/wp-bootstrap-navwalker

  2. put this file in the root folder of the theme and in the functions.php file
    userequire_once get_template_directory() . '/wp-bootstrap-navwalker.php';

  3. finally you’ll have to add following parameters:

    $defaults = array(
      'container' => false,
      'theme_location' => 'primary-menu',
      'menu_class' => 'nav navbar-nav navbar-right',
      'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
      'walker' => new WP_Bootstrap_Navwalker(),
    );
    wp_nav_menu($defaults);
    

especially last two parameters to your wp_nav_menu() function.

I hope it helps

Leave a Comment