传递给过滤器的第三个参数是$args
用于wp_nav_menu
:
function wpse_147499_nav_menu_css_class( $classes, $item, $args ) {
print_r( $args );
exit;
}
add_filter( \'nav_menu_css_class\', \'wpse_147499_nav_menu_css_class\', 10, 3 );
。。。这将为您提供:
stdClass Object
(
[menu] =>
[container] =>
[container_class] =>
[container_id] =>
[menu_class] =>
[menu_id] =>
[echo] => 1
[fallback_cb] =>
[before] =>
[after] =>
[link_before] =>
[link_after] =>
[items_wrap] =>
[depth] => 0
[walker] =>
[theme_location] =>
)
显然,这些菜单的值各不相同,永远不要假设其中一个菜单总是非空的,但希望您能够区分不同的菜单。