你只需要第三个论点$args
, 其中一个属性是theme_location
:
function wpse_218377_nav_menu_css_class( $classes, $item, $args ) {
if ( ! empty( $args->theme_location ) && $args->theme_location === \'custom-menu\' ) {
$classes[] = \'footer--menu-item\';
}
// ALWAYS return, not from inside the if
return $classes;
}
add_filter( \'nav_menu_css_class\' , \'wpse_218377_nav_menu_css_class\' , 10, 3 );