You are checking against just one parent item.
Instead, you might check against all of the parents
<?php //in functions.php
add_filter('nav_menu_css_class', 'highlight_portfolio', 12, 2);
function highlight_portfolio($classes, $item) {
$parents = get_post_ancestors();
if ( 0 < count($parents) ) {
if ( in_array( $item->object_id, $parents ) {
array_push( $classes, 'current-menu-ancestor' );
}
}
return $classes;
}
Notice in your code
$parent_ID = $parent[0];
That only grabs the first parent id in the list returned. Using in_array checks to see if it matches any of the ancestors.
Related Posts:
- Breadcrumbs showing Parent and Child Pages
- automatically adding submenu items
- Logout hyperlink within a sub-menu
- Custom Nav Walker sub-menu
- retrieves menu and converts it to a readable array
- Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
- why is this function firing on all child menu items as well?
- Unable to add extra elements to the main navi (wp_nav_menu_items)
- Conditional custom menu?
- Modify sub_menu function to show pages below a specifically set page
- How do I get my nav menu to show sub pages?
- How to add a data attribute to a WordPress menu item
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Get menu object from theme_location
- Remove a menu item created by a plugin
- Remove Container Element From wp_nav_menu() Markup
- Using wp_get_nav_menu_items() to list children of children pages
- How to target specific wp_nav_menu in function?
- How can I programmatically create “child” pages on theme activation?
- Custom menus displaying all pages instead of set pages
- Return only top-level navigation items from a menu using wp_get_nav_menu_items
- How to activate “Description” metabox for menu item programmatically?
- Breadcrumb how i can display page title with parent > child title with permalink ? any Idea
- Two different menus for two different locations?
- How to programmatically set a menu to be the Primary Menu?
- Editing or filtering the output of the Genesis navigation
- Query children and parent title
- Make menu structure match page heirarchy on page parent change
- Menu fallback “menu_class” rendering a “div” instead of a “ul”
- List child pages of specific page using shortcode
- CSS for menu item added via functions.php
- How To Remove Duplicate Menu Locations
- Where do I add html code to the menu div?
- Replace menu links with # and add name to its li
- How to get specified parent page title in my function
- How do I create page navigation linking to each H2 within the page? [closed]
- Function issue with Walker_Nav_Menu [duplicate]
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- Schedule Page to Menu [duplicate]
- Make parent page only link to first subpage
- How to add nav menu items to a specific position within a menu
- wp_nav_menu, walker class, categories as classes of li
- Hard-coding custom menu elements for menu manager
- How to retrieve parent menu item name of current submenu item
- How to fetch the name of the active menu?
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Categories as main menu items and subcategories as nested lists
- get_the_title() gets printed out twice
- Removing specific menu items?
- How to highlight 1st level menu item based on actual page
- How do I hook into the container of wp_nav_menu?
- New custom menu created. how to apply it?
- Dropline menus — seperators between children only?
- Filter nav menu items HTML tags and wrap inner text with span
- Functions php shortcode for displaying main menu with no child items
- Nav menus all outputting the same links
- Secondary Menu and Logged In Users
- Change menu based on page template via functions.php
- Show some menu sub items as dropdown under a menu item
- How to add custom li item to wordpress menu
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- Default Nav Highlight
- Different methods of adding menu support to custom theme
- Adding a section in line at the end of the main navigation menu in php
- Multiple navigation menu in same location
- Do we need to change our child function.php to require/include child dir files when we add an over-riding file.php into the child theme
- wp_nav_menu work in functions.php but not in the theme
- How to register a menu based on a ACF condition
- Sort and display pages with specific custom field (not tag)
- current_page_item is missing inside wp_nav_menu
- search form leads to 404
- How Can I add a menu to the theme from withen the function.php file
- define css class in functions.php
- Add Login and logout buttons to top menu bar
- Custom Menu in Admin doesn’t change menu in browser
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- wp_nav_menu displaying all pages
- Warning at top of website & top menu gone
- How to display an image before title text in menu items
- Bizarre Child Menu Issue on WP Site
- Header menu aligned right on all pages except for single-post page [closed]
- How to automatically add counted number to navigation menu items?
- Combine multiple menus using the filter wp_nav_menu_items
- Creating navigation out of specific IDs and their children?
- Menu and category highlighting for a single post
- Display list of pages that contain a certain string within the slug
- Language Switch Function
- Insert menu into theme location depending on user logged in/out status
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- How I can add div to menu?
- Adding custom field in menu options [duplicate]
- Adding a filter with custom function to the menu / navigation
- How to add a class name to the ancestor of a post?
- Function Reference for custom link in Admin Menu Management Page
- Notice: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ in ….functions.php on line 73
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- Call wordpress function through functions.php when pressing menu
- How to add more than one menu for logged in members?