ControlledChaos of Controlled Chaos Design
8/9/2016 - 6:41 PM

Highlight Menu Item for Custom Post Types

Highlight Menu Item for Custom Post Types

<?php

function ccd_namespace_menu_classes( $classes , $item ){
	if ( get_post_type() == 'event' || is_archive( 'event' ) ) {

		$classes = str_replace( 'current_page_parent', '', $classes );

		if ( $item->url == '/events' ) {
			$classes = str_replace( 'menu-item', 'menu-item current_page_item', $classes );
			remove_filter( 'nav_menu_css_class', 'namespace_menu_classes', 10, 2 );
		}
	}
	return $classes;
}
add_filter( 'nav_menu_css_class', 'ccd_namespace_menu_classes', 10, 2 );

?>

Highlight Menu Item for Custom Post Types

WordPress Snippet