wordpress - How to add "active" class to wp_nav_menu() current menu item (simple way) -
wordpress - How to add "active" class to wp_nav_menu() current menu item (simple way) -
i creating custom wordpress theme using starter theme _underscores. using bootstrap front-end framework.
i modify wp_nav_menu assigns current menu item class="active" instead of class="current-menu-item" (which default). or maybe @ to the lowest degree assigns both of these classes. need in order utilize .active class bootstrap.css.
here illustration of have (all these classes wp generated, please scroll see mean):
<ul id="menu-main-menu" class="nav navbar-nav"> <li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-13 current_page_item menu-item-14"><a href="">item1</a></li> <li id="menu-item-12" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-12"><a href="">item2</a></li> </ul>
and here need:
<ul id="menu-main-menu" class="nav navbar-nav"> <li id="menu-item-14" class="active menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-13 current_page_item menu-item-14"><a href="">item1</a></li> <li id="menu-item-12" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-12"><a href="">item2</a></li> </ul>
i prefer in right way - don't want alter in ..wp-includes/nav-menu-template.php sure, don't want utilize js either.
well found reply before posting question (it ready, that's why still formed in way if still seeking answer), had rather hard time finding decided post qa. hope find useful.
just paste code functions.php file:
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2); function special_nav_class ($classes, $item) { if (in_array('current-menu-item', $classes) ){ $classes[] = 'active '; } homecoming $classes; }
try link1,link2 source:
wordpress menuitem
Comments
Post a Comment