如何使用Wordpress在菜单中添加Active类
问题描述:
How to add Class in active menu in wordpress. I have use below Code. but it's not working please help me
wp_nav_menu( array(
'container' => '',
'items_wrap' => '%3$s',
'theme_location' => 'primary'
) );
如何在wordpress的活动菜单中添加Class。 我使用下面的代码。 但是它不起作用请帮帮我 p>
wp_nav_menu(array(
'container'=>'',
'itements_wrap'=>'%3 $ s',
'theme_location'=>'primary'
));
code> pre>
div>
答
please add this code in your nav-menu-template.php file in line number near about 149.
$item_output .= '<a'. $attributes .' class="'.$classes[0].'" >';
Now on this case your css class apply to href link and you want to just add this class in admin side menu css classes.
let me know once done.
答
Add the following to functions.php
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 ';
}
return $classes;
}
See the Codex for further reading
答
please add this code in your nav-menu-template.php file in line number near about 149.
$item_output .= '<a'. $attributes .' class="'.$classes[7].'">';
before add this code it will look like this
<a href="#">Home</a>
after add this code it will look like this
<a class="current_page_item" href="www.gooole.com">Home</a>
on that your <li>
current class is display on link menu item class