0

I'm creating a theme using bootstrap and now I want to display the menu adapting it to bootstrap... so I'm using the Upbootwp_Walker_Nav_Menu to achieve this, and also sending some args to the wp_nav_menu but the result is not what I expected. This is the method which I'm calling on header.php

<?php wp_nav_menu(array( 'theme_location' => 'primary',
                                            'container' => 'nav',
                                            'container_class' => 'collapse navbar-collapse bs-navbar-collapse',
                                            'items_wrap'=>'<ul id="%1$s" class="nav navbar-nav %2$s">%3$s</ul>',
                                            'walker' => new Upbootwp_Walker_Nav_Menu()
                                    )); ?>

also I had to add a method to the filter on the functions.php

add_filter('wp_nav_menu_args','specialist_nav_menu_args');

function specialist_nav_menu_args($args){
    if($args['theme_location']=='primary'){
        $args['container'] = 'nav';
        $args['container_class'] = 'collapse navbar-collapse bs-navbar-collapse';
        $args['items_wrap'] = '<ul id="%1$s" class="nav navbar-nav %2$s">%3$s</ul>';
        $args['container_id'] = 'menu_primary';
    }
    return $args;
}

I was supposed after adding this changes, the menu will display correctly but if I see the html generated... this is what I see:

<div class="collapse navbar-collapse">
   <ul>
      <li class="current_page_item">
         <a href="http://localhost/wp-musi/">Home</a>
      </li>
      <li class="page_item page-item-2">
         <a href="http://localhost/wp-musi/sample-page/">Sample Page</a>
      </li>
   </ul>
</div>

So first: as I declare thar the container will be a <nav>, then that will have the class collapse navbar-collapse. So what am I doing wrong? I've read the documentation of this method here but it seems like not recognizing the parameters I am sending

1 Answer 1

2

WordPress navigation menus won't conform to styling or coding changes if they are being built by default.

You have to actually go in and create the menu in Appearance > Menus and assign it to the menu location. After you do that, it should conform to coding/styling standards you set, as opposed to system defaults.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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