这样可以帮助您筛选菜单项并有条件地添加自定义类。(未经测试)
function add_nav_class( $classes ) {
if ( class_exists( \'current-menu-ancestor\' ) || $item->title == \'blog\' ) {
$classes[] = \'current-menu-grand-ancestor\';
}
return $classes;
}
add_filter( \'nav_menu_css_class\', \'add_nav_class\', 10, 2 );