How to add custom nav_menu_css_class to certain menu only?

Question

I want to add a custom CSS class to menu items. So far, I got it working by using the filter hook nav_menu_css_class.
However, I want to add this class to items of a specific menu only. So, how must a condition look like to affect a specific menu (e.g. ‘custom-menu’ in theme_location ‘footer_menu’) only?

function add_footer_nav_item_class( $classes, $item ) {
  // I am looking for a condition here
  if ($item belongs to 'custom-menu'){
    $classes[] = "footer--menu-item";
    return $classes;
  }
}
add_filter( 'nav_menu_css_class' , 'add_footer_nav_item_class' , 10, 2 );
0
, , Bunjip 7 years 2016-02-21T08:42:00-05:00 0 Answers 81 views 0

Leave an answer

Browse
Browse