Define your own classes for active page list item in wp_nav_menu()

Ok, so i guess one of the most common problems i’m having when doing HTML -> WordPress conversions is that when coding up the HTML noone puts “current_menu_item” class for the active list item in the navigation, neither do i, i prefer “active” or “current”.

So then when it needs to be converted to WordPress i need to go in the CSS and change the class to current_menu_item and i was very tired of doing that every time so i dived in into the core and figured out a way to add classes to active page list item.

add_filter( 'nav_menu_css_class', 'additional_active_item_classes', 10, 2 );

function additional_active_item_classes($classes = array(), $menu_item = false){
	
	if(in_array('current-menu-item', $menu_item->classes)){
		$classes[] = 'active';
	}
	
	return $classes;
}

I guess this will benefit every WordPress developer, so i thought i can post it here. I would put up the link to the original post with this code snippet but self promotion isn’t allowed.

Anyway, i hope you’ll find this useful.