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;
}
Related Posts:
- Display a portion/ branch of the menu tree using wp_nav_menu()
- Unregister Nav Menu from Child-Theme
- Display only page specific sub menu items using Custom Walker
- Custom settings disappear during database migration?
- Call custom field into menu item
- Exclude Private, Draft pages from Primary Nav when using custom menu
- Automatically remove trashed pages from nav menu
- Pulling Featured Images in to a WordPress Menu
- wp_nav_menu always falls back to a menu
- Menu Disappears on Category Pages
- Overriding wp_nav_menu default arguments
- Move admin menu at the end
- Should the caching of WordPress menus be specific to each page?
- Not able to get current menu ID
- How to implement my own icons instead of using the svg icon system
- wp_nav_menu (secondary menu) not adding current classes
- WordPress wp_nav_menu with a nav tag
- How can I detect whether a BuddyPress page is active from within my theme?
- WP /wp-admin/admin-ajax.php produces 404
- `start_el` depth argument in custom nav walker always evaluates to zero
- Programmatically set current-menu-item using wp_nav_menu
- Custom Admin Menu Order
- How to set classname for tag in wordpress menu?
- How can I add divs or change li in the submenu of the menu_nav
- Get number of root elements in walker class
- Operable default menu *and* custom 3 menu
- WordPress menu permalink redirects to wrong page
- HTML to WordPress Menu convert
- How to change menu URLs to hashes?
- How to create this Custom Walker Menu
- create a 2 row menu in wordpress
- Get menu item by name or slug
- How to handle many different menus?
- wp_page_menu not working right?
- using OOP approach to create plugin but stuck at making hyperlinks to work
- creating a custom walker class
- Adding menu items?
- Adding existing links to custom navigation menus?
- How to truncate menu label in wordpress?
- Is it possible to add a dynamic link in the main navigation in a child theme
- How to change menu structure?
- magic “MENU” button under Twenty Twelve theme
- Remove first separator in wp_nav_menu
- wp_nav_menu check both hierarchy fail?
- Edit the (automatic) HTML layout of nav menus
- Add custom path to url to specific pages
- CTA button that is only visible to some of my users
- How do add a menu with levels within page [closed]
- Hide menu item when users are logged in/out
- add another html tag after li element in wp_nav_menu
- menu-item class missing on wordpress menu
- How to add scroll IDs to WordPress menu anchors
- Active class to current link
- Making pages in a menu appear conditionally
- Modify the output of wp_nav_menu in a very specific way?
- Display pictures instead of text in menus
- how to check if given page is active page
- how to set the link in wordpress such that on clicking it doesn’t open another page but go to the bottom of same page
- How to add social buttons like facebook and twitter in the footer of a theme?
- WordPress Menu – creating a fake link [closed]
- How to add an archive page to WordPress menus (nav_menu)?
- Add div content to my already existing menu
- Hiding menu on specific pages
- Add category label for appearance > menus items
- Custom items for Menus
- sidebar navigation problem with child pages not all display.?
- How to point menu to my homepage
- dot.com/car1 does work, but dot.com/transport/car1 doesn’t work
- code to add an extra selection to the menu editor
- WP pages content is missing in frontend
- Active menu item state on all menu items
- Dashicons not showed for admin menu
- How to select particular menu position in wordpress?
- Menus not visible in Appearance after being registered
- Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()
- Cannot add home page url to menu with #
- Accidental reverse order of menu items in one menu
- Having an issue with wp_nav_menu displaying custom navigation
- Add dynamic content block to nav section generated by custom walker
- Customizing label/title output of admin nav_menu selecter
- Extend Individual Menu on Page Function to individual Submenue on Page Function?
- How do I remove a menu from a theme?
- Menu administration, how to allow special charachters
- How to avoid website url appending problem in wp site?
- Create custom page and custom menu
- Get first menu item of custom menu
- How can I modify wp_nav_menu with walker?
- menu items outside of blog
- Walker for menus
- Bought custom navigation menu from codecanyon, how to change feature.php?
- Custom menu linking to page not found
- How to insert date in topNav
- Change sub-menu css class
- How to add an tag when a menu item is a dropdown(or has a sub-menu) [duplicate]
- Remove “Next Post” in nav_menu
- How to display a submenu as a popup when clicking a button?
- Menu not Showing on Mobile or While the page is shrinked
- My Menu Disappears on my Custom Link Homepage on Mobile
- How do i add logo in wordpress studiopress (glam theme)?
- Add A Menu Item To A WP_Nav_Menu Navigation via PHP Function