CSS, Nav Menu, PHP | Type: PHPAdd current class to post type navigation menu

The examples show posts (where the homepage is the blog list), but this works for any custom post type as well. I’ve used it forever; don’t remember where I got it from. This can go in your theme’s functions file or in a file in the mu-plugins folder.

//  ADD "CURRENT" CLASS TO SPECIFIED POST TYPE
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
	 if(is_singular('post') && $item->title == "Home"){ 
        $classes[] = "current_page_ancestor";
     }
     if(is_archive('post') && $item->title == "Home"){
		 $classes[] = "current_page_ancestor";
     } 
      if(is_paged('post') && $item->title == "Home"){
		 $classes[] = "current_page_ancestor";
     }
     return $classes;
}