示例
导航菜单漫游器-允许将css类添加到(所有)菜单项。
// copyied from /wp-core/wp-includes/nav-menu-template.php > line 76 (wp 3.1.1) - start_el() function
$class_names = join( \' \', apply_filters( \'nav_menu_css_class\', array_filter( $classes ), $item, $args ) );
现在让我们检查一下$var:
function wpse15319_check_nav_menu_classes( $classes )
{
// You can take any of the $vars from the core function above: $classes, $item, $args
echo \'<pre>\';
// nice list:
print_r( $classes );
// or check of what type the $var is
var_dump( $classes );
echo \'</pre>\';
return $classes;
}
add_filter( \'nav_menu_css_class\', \'wpse15319_check_nav_menu_classes\', 10 );
修改-应用示例
function wpse15319_add_nav_menu_classes( $classes )
{
$classes[] = \'\';
$classes[] .= \'my added css classes\';
return $classes;
}
add_filter( \'nav_menu_css_class\', \'wpse15319_add_nav_menu_classes\', 10 );