WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

enter image description here

share|improve this question

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

 
discard

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.