I am learning wordpress
together with bootstrap
and somehow I can't add class
on UL
tag.
In the screenshot, I want to add class nav nav-tabs
on UL
but it was added on parent div
$defaults = array( 'menu_class'=> 'nav nav-tabs', ); wp_nav_menu( $defaults );
Inspected element:
Referrence:
http://codex.wordpress.org/Function_Reference/wp_nav_menu
First of all, you need to create a custom navigation menu from Appearance -> Menus . Then, use the wp_nav_menu with the following parameters: <? php $args = array( 'menu_class' => 'nav nav-tabs', 'menu' => '(your_menu_id)' ); wp_nav_menu( $args ); ?>
Optionally, you may want to add the option to add classes to list items: function add_menu_list_item_class($classes, $item, $args) { if (property_exists($args, 'list_item_class')) { $classes[] = $args->list_item_class; } return $classes; } add_filter('nav_menu_css_class', 'add_menu_list_item_class', 1, 3);
Usage. wp_nav_menu( $args ); Given a theme_location parameter, the function displays the menu assigned to that location. If no such location exists or no menu is assigned to it, the parameter fallback_cb will determine what is displayed.
To do this go to Appearance >Menus and start creating a new menu. Give the menu the title “Secondary Menu”, select “My Custom Menu” for a location and then hit the “Create Menu” button. Finally add some items to the menu (for example Menu item 1, Menu item 2, Menu item 3) and then save the menu.
First of all, you need to create a custom navigation menu from Appearance -> Menus
.
Then, use the wp_nav_menu
with the following parameters:
<?php $args = array( 'menu_class' => 'nav nav-tabs', 'menu' => '(your_menu_id)' ); wp_nav_menu( $args ); ?>
There's a lot you can read about Wordpress Menus. I suggest the following:
http://codex.wordpress.org/Navigation_Menus
http://www.paulund.co.uk/how-to-register-menus-in-wordpress
You need to specify the container element, in our case 'ul'
tag, and than specify the class that we will assign in 'menu_class'
. Here is the sample code:
wp_nav_menu( array( 'theme_location' => 'top-menu', 'container' => 'ul', 'menu_class'=> '[add-your-class-here]' ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With