Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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


enter image description here

share|improve this question

1 Answer 1

Do 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')

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.