admin管理员组文章数量:1122846
While on any given link that has a CSS Classes value, I'd like to do something like this:
$css_classes = get_current_menu_item_css_classes();
if ( $css_classes == 'mycustomclass' ) : // do something
Thanks
While on any given link that has a CSS Classes value, I'd like to do something like this:
$css_classes = get_current_menu_item_css_classes();
if ( $css_classes == 'mycustomclass' ) : // do something
Thanks
Share Improve this question asked May 6, 2014 at 19:49 Tai SemTai Sem 811 silver badge11 bronze badges2 Answers
Reset to default 0Do not know if it's exactly what you're looking for but this short snippet adds custom classes to nav menu item :
add_filter('nav_menu_css_class' , 'wpse_143574_nav_class' , 10 , 2);
function wpse_143574_nav_class($classes, $item){
$classes[] = "my-class";
}
return $classes;
}
This could be modified with some conditional tags too.
EDIT: $item
is often useful for example if ( $item->title == 'Contact')
You can do something this like:
// where "Top" is menu name, slug or id. But not menu location.
$menu_items = wp_get_nav_menu_items( 'Top' );
foreach ( $menu_items as $menu_item ) {
$menu_classes = $menu_item->classes;
foreach ( $menu_classes as $menu_class ) {
if ( 'mycustomclass' === $menu_class ) {
return true;
}
}
}
本文标签: How to get current menu item quotCSS Classesquot value
版权声明:本文标题:How to get current menu item "CSS Classes" value? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291721a1928783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论