我想禁用默认菜单类,下面的代码是完全禁用菜单类。
add_theme_support( \'menus\' );
add_filter(\'nav_menu_css_class\', \'my_css_attributes_filter\', 10, 1);
add_filter(\'nav_menu_item_id\', \'my_css_attributes_filter\', 100, 1);
add_filter(\'page_css_class\', \'my_css_attributes_filter\', 100, 1);
function my_css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array(\'current-menu-item\', \'current-menu-ancestor\')) :
\'\';
}
但现在的问题是,即使我在菜单中添加自定义类
实例
navcon 那节课不来了。我了解一点是因为
add_filter(\'nav_menu_css_class\', \'my_css_attributes_filter\', 10, 1);
所以,有没有办法只禁用所有default类,但如果有自定义类,那么它将添加
我的践踏代码是<?php wp_nav_menu( array(\'menu\' => \'mainmenu\',\'items_wrap\'=>\'%3$s\', \'container\' => false)); ?>
最合适的回答,由SO网友:pagol 整理而成
我从另一个帖子得到了答案。。这就是贝娄
add_filter(\'nav_menu_css_class\', \'discard_menu_classes\', 10, 2);
function discard_menu_classes($classes, $item) {
$classes = array_filter(
$classes,
create_function( \'$class\',
\'return in_array( $class,
array( "current-menu-item", "current-menu-parent" ) );\' )
);
return array_merge(
$classes,
(array)get_post_meta( $item->ID, \'_menu_item_classes\', true )
);
}
参考号:
http://wordpress.stackexchange.com/questions/30417/removing-all-classes-from-nav-menu-except-current-menu-item-and-current-menu-par