Blacklist Menu Item Classes

/**
 * Clean Nav Menu Classes
 *
 */
function ea_clean_nav_menu_classes( $classes ) {

	if( ! is_array( $classes ) )
		return $classes;

	$remove_classes = array(
		'menu-item-type-custom',
		'menu-item-type-taxonomy',
		'menu-item-object-custom',
		'menu-item-object-category',
	);

	$classes = array_diff( $classes, $remove_classes );

	foreach( $classes as $i => $class ) {

		// Remove class with menu item id
		$id = strtok( $class, 'menu-item-' );
		if( 0 < intval( $id ) )
			unset( $classes[ $i ] );
	}

	return $classes;
}
add_filter( 'nav_menu_css_class', 'ea_clean_nav_menu_classes', 5 );

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk