は、最後にそれを行う方法が見つかりました:
$main_gallery_page= get_page_by_title('Galleries');
add_filter('nav_menu_css_class' , 'force_ancestor_nav_class' , 10 , 2);
function force_ancestor_nav_class($classes, $item){
global $main_gallery_page,$post;
//condition: could be any condition: by category, title, contents, ...
$make_ancestor=substr($post->post_title, 0, 7) === "Gallery";
//only adds the class if the condition is met and not already present
if ($item->object_id==$main_gallery_page->ID && $make_ancestor && !in_array('current-page-ancestor',$classes)) {$classes[]='current-page-ancestor';}
return $classes;
}