I want to highlight the parent of a child page in the menu when the child page itself is not in the menu.
I know this would work if you add the child as a sub page but that isn’t the case.
Any ideas?
I want to highlight the parent of a child page in the menu when the child page itself is not in the menu.
I know this would work if you add the child as a sub page but that isn’t the case.
Any ideas?
Alrdy got it:
<?php //in functions.php
add_filter('nav_menu_css_class', 'highlight_portfolio', 12, 2);
function highlight_portfolio($classes, $item) {
$parent = get_post_ancestors();
$parent_ID = $parent[0];
if ($parent_ID == $item->object_id) {
array_push($classes, 'current-menu-ancestor');
}
return $classes;
}