<ul class="nav navbar-nav navbar-right">
          <a class="page-scroll" href="#about">About</a>
          <a class="page-scroll" href="#features">Features</a>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Pages <span><img src="<?php /*echo get_theme_file_uri( 'assets/img/icons/caret.svg' );*/ ?>" alt=""></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
          <a class="page-scroll" href="#feedback">Feedback</a>
          <a class="page-scroll" href="#pricing">Compare</a>

how can I add those classes present in li tag using the wp_nav_menu() function?

        $defaults = array(
          'container' => false,
          'theme_location' => 'primary-menu',
          'menu_class' => 'nav navbar-nav navbar-right'
  • You can't, you need a custom walker. If you're using Bootstrap one already exists that you can use: github.com/wp-bootstrap/wp-bootstrap-navwalker – Jacob Peattie Dec 21 '17 at 6:20
  • appreciated your help but It's still not working. The whole dropdown list is displaying. – maverick Dec 21 '17 at 6:35
  • By default wordpress provides dropdown menus, you can use scripts and style to adjust that. – Rajilesh Panoli Dec 21 '17 at 7:56

Problem solved guys thanks to Rajilesh Panoli, from github link provided in the above comment. download wp-bootstrap-navwalker.php and copy that file to your root directory of the theme and include that file in your functions.php file, then use following code:

'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
          'walker' => new WP_Bootstrap_Navwalker(),

in the wp_nav_menu() function in the header.php file (or wherever you have used this function).

| improve this answer | |

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.