If I understand it properly, this would do what you wanted:
function my_special_nav_class( $classes, $item ) {
if (
// 1. The menu item is for the "/events" page. Be sure to change the "123"
// (i.e. the "/events" page ID).
( 'page' === $item->object && 123 == $item->object_id ) &&
// 2. The current page is "Past Events" or that it's a "Event" single page.
// If "event" isn't the correct post type, change it.
( is_page( 'past-events' ) || is_singular( 'event' ) )
) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 );
UPDATE
So if the /events
menu item is a custom link:
function my_special_nav_class( $classes, $item ) {
if (
( 'custom' === $item->type && 'events' === $item->post_name ) &&
( is_page( 'past-events' ) || is_singular( 'event' ) )
) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 );
If that does not work, then try checking against the menu item ID (here it’s 456
):
function my_special_nav_class( $classes, $item ) {
if (
456 == $item->ID &&
( is_page( 'past-events' ) || is_singular( 'event' ) )
) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 );