我不知道你每门课的条件是什么nav_menu_css_class
. 您可以使用它来附加类或从每个列表项中删除类<li>
在菜单中。
/**
* Modify list item classes of wp_nav_menu
* - https://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_css_class
* - https://developer.wordpress.org/reference/hooks/nav_menu_css_class/
*
* @param Array $classes || List of list-item classes
* @param WP_Nav_Item Object $item || The Nav Menu Object, NOT the WP_Post object
*
* @return Array $classes
*/
function my_special_nav_class( $classes, $item ) {
$menu_to_test_against = \'MENU NAME HERE\';
// Ensure we only apply this filter on the menu of our choice
if( ! has_term( $menu_to_test_against, \'nav_menu\', $item ) ) {
return $classes;
}
$classes[] = \'nav-p\';
$classes[] = \'nav-n\';
return $classes;
}
add_filter( \'nav_menu_css_class\', \'my_special_nav_class\', 10, 2 );