I have two custom post types, and I have trouble adding the current-menu-item to both. In my functions.php I have following code:
function additional_active_item_classes($classes = array(), $menu_item = false){
global $wp_query;
if(in_array('current-menu-item', $menu_item->classes)){
$classes[] = 'current-menu-item';
}
if ( $menu_item->post_name == 'portfolio' && is_post_type_archive('portfolio') ) {
$classes[] = 'current-menu-item';
}
if ( $menu_item->post_name == 'portfolio' && is_singular('portfolio') ) {
$classes[] = 'current-menu-item';
}
if ( $menu_item->post_name == 'freebies' && is_post_type_archive('freebies') ) {
$classes[] = 'current-menu-item';
}
if ( $menu_item->post_name == 'freebies' && is_singular('freebies') ) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'additional_active_item_classes', 10, 4 );
I know this is maybe not the most optimized code but most important to get it work. You can see the site here:
On portfolio it's working but not on the freebies. Why? Thanks so much in advance
Aucun commentaire:
Enregistrer un commentaire