Trying to add current_page_item to multiple archive pages is functions

I’ve had to add a function to add the current_page_item class to my menu items in my wordpress theme as a couple of pages are archives so don’t display this class.

The first one worked fine but the subsequent ones aren’t displaying the class.

I’m not very hot with PHP, so any help would be appreciated:

function add_nav_menu_classes($classes, $item){
if( is_post_type_archive(‘prints’) && ($item->title == “Prints” ) ){
$classes[] = ‘current_page_item’;
}
return $classes;
}
add_filter(‘nav_menu_css_class’ , ‘add_nav_menu_classes’ , 10 , 2);

function add_nav_menu_classesb($classes, $item){
if( is_post_type_archive(‘fashion’) && ($item->title == “Fashion” ) ){
$classes[] = ‘current_page_item’;
}
return $classes;
}
add_filter(‘nav_menu_css_class’ , ‘add_nav_menu_classes’ , 10 , 2);

I’m not sure if my renaming of the function is the fault (but the same function name breaks the site). I think it would be better to truncate this code into one function, but I’m not smart enough to code it this way..

Thanks, M

Read more here:: Trying to add current_page_item to multiple archive pages is functions

Leave a Reply

Your email address will not be published. Required fields are marked *