Adding Conditional Classes to Menu Items
此示例允许您根据指定的条件向菜单项添加自定义类。别忘了改变条件。
<?php
add_filter(\'nav_menu_css_class\' , \'special_nav_class\' , 10 , 2);
function special_nav_class($classes, $item){
if(is_single() && $item->title == "Blog"){ //Notice you can change the conditional from is_single() and $item->title
$classes[] = "special-class";
}
return $classes;
}
?>
还可以看看
How to Add a Custom Class to a WordPress Menu Item.