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 );