0

I have this 'primary' menu with a few items in the CMS, which I can list nicely with this PHP code:

$args = array(
    'theme_location' => 'primary'
);

wp_nav_menu( $args ); 

The PHP outputs the menu with the <ul> tag. but, I want to use HTML that looks like this:

<ul class="nav navbar-nav">  
    <!-- primary menu items -->
</ul>

I'm looking for the right way to output my primary menu with the HTML from above.

  • You likely will need a Bootstrap compliant Menu Walker to fulfill your needs, perform a (re-)search on the net to find more information on that. – Nicolai Mar 31 '16 at 11:42
1

You can change the classes of the <ul> by adding 'menu_class'=>'nav navbar-nav' to your $args array. Remember, this parameter overwrites all the classes, so add "menu" as well if you want many themes and plugins to work!

If you don't want the outer <div>, you can "unwrap" the <ul> by adding 'container'=>false.

$args = array(
    'theme_location' => 'primary',
    'menu_class'     => 'nav navbar-nav',
    'container'      => false,
);

See the full reference here.

0

From your question i'm guessing you don't want wrapping divs around your tags. To remove them just add that extra line to your $args. If this is not the answer can you please specify the problem.

$args = array(
    'theme_location' => 'primary',
    'container' => ''
);

wp_nav_menu( $args );

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.