不确定,但也许像这样的事情会奏效?添加到函数。php。请参见说明here.
//This function is responsible for adding "my-parent-item" class to parent menu item\'s
function add_menu_parent_class( $items ) {
$parents = array();
foreach ( $items as $item ) {
//Check if the item is a parent item
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
}
foreach ( $items as $item ) {
if ( in_array( $item->ID, $parents ) ) {
//Add "menu-parent-item" class to parents
$item->classes[] = \'my-parent-item\';
}
}
return $items;
}
//add_menu_parent_class to menu
add_filter( \'wp_nav_menu_objects\', \'add_menu_parent_class\' );
因此,如果可以使用Jquery,可以这样做:
$(\'ul li.menu-parent-item:has(ul ul)\').addClass(\'your class\');