What you’ll need to do is use get_ancestors()
. Pass get_ancestors()
your current page ID, and then search the resulting array for the menu item ID. If the menu item ID is in the array, set the class to active.
Related Posts:
- WordPress – site with 2 stylesheets and more…
- How to apply a class to the second word in menu list item?
- List children of second level sub page
- How to get current page menu item name instead of full menu item list
- Styling child custom menu pages
- How to highlight the current page in the nav menu?
- How do I prevent the text overflow in menu?
- How to change Twenty Seventeen theme’s navigation bar location?
- Making WordPress’ page and menus visible only for logged in users, checking session variables
- How do i style the current menu anchor link’s parent anchor link? [closed]
- Custom Post type menu highlighted in the archive/post
- Getting post content within wp_nav_walker
- wp_list_pages sort order is different for different languages [closed]
- list pages only from master parent
- wp_list_pages: only show subpages on the parent page?
- Altering html structure and creating custom menus
- Auto add pages to primary menu with functions.php
- Does loading of sub pages in menu cause load to the server?
- How to add class to and childs of sidebar widget – WordPress
- Link to Homepage in Menu
- Add CSS to head depending on nav menu walker
- CSS for Created Menu “Active Selected” not working, everything else is!
- How do I add (css) class to a custom link to make it current_page_item
- wp_nav_menu not working [closed]
- Programmatically add existing pages and subpages to Appearance Menu
- How to retrieve parent menu item name of current submenu item
- two different separate sections on the same site
- When clicking on menu item not going to specific page
- Static page to one page- menu inactive items highlighted
- Ad custom admin page like WordPress customizer [closed]
- CSS_Menu_Walker not showing on mobile view?
- CSS Classes (optional) on menu is not showing
- Create custom page and add it in nav menu by code
- Does is_child() exist in wp 3.5.1?
- wp_list_pages sort order by custom nav menu order
- How to highlight 1st level menu item based on actual page
- Prevent menu from loading in a page template [duplicate]
- How to I know the class or ID of my theme?
- My Temptation theme is showing two of the same menu at the top. How do I remove the one that the theme comes with? Please help! [closed]
- Highlight parent if item from submenu is active
- WordPress + Bootstrap [closed]
- How to add a page to header that is outside of WordPress?
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Navigation menu not visible (contrast issue) on home page
- Add (grand)child pages automatically to nav menu
- how avoid the link of the current post in the menu in the sidebar?
- Page appears after de registering from menu
- Full screen nav menu block with avada theme
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- Drop Down menu expanded by default (on front page) [closed]
- Parent Page > Child Page Menu
- Controlling sub-menu within sub-menu
- Main menu navigation links and new pages
- Page header menu links change
- Catagorized hierarchy menu for PAGES!
- Styling issue with custom menus and sub menus
- Page dependent sub-menu?
- Making the menu toggled open on mobile devices Illustratr theme
- adding pages in underscores.me theme
- How to get the Page Name of the current page?
- How to add CSS class to and and id in a nav menu with code?
- Change hover to onclick on menu
- Add/remove image from navigation bar
- Add CSS Class to WordPress Menu Item Dependent on the Page the User is Visiting
- How can I order these pages in this navigation bar on this old wordpress theme?
- How to create a mobile menu full screen overlay using Understraps Bootstrap 4 theme
- Additional CSS for the nav menu
- Active Current Menu – Adding class to child theme
- Adding span to a particular text in an menu item
- Unable to remove page from primary menu
- Get Sub-Menu Dropdown to Show Over Page Content
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- Mark a page of a queried menu as active
- Adding two same css class on menu item
- Two questions about CSSing inside the menus
- Always show wordpress submenu on responsive header menu
- Specific Page that convert Hyperlink to anchor in nav menu
- Menu item hidden behind others
- Active page link not getting class assigned
- WordPress – Apperance > Menu
- Active menu item / category
- jQuery not working when used with wordpress menu
- Making a Custom Menu Sidebar Icon show as Current in css [closed]
- Creating and populating custom nav menu (menu-item-position not working)
- Help with changing style of the extended menu drop down [closed]
- How do i keep my current page menu highlighted on pagination?
- Can’t style custom menu
- Styling Active Links Within WordPress
- Menu Underline shows without Hover after adding subitems
- Site with all content on the front page
- Problem with float:left – unexpected behavior [closed]
- Changing color of specific tab of top menu
- Why is my hamburger menu not shown? [closed]
- Keeping my Sub Menu open when hovering on its list items
- Formatting WordPress Menus (without bullets, inline with text)
- Adding padding above menu
- How can I only show one responsive menu on mobile devices?
- change breakpoint widths for divi theme tablet view
- Control page access based on User Meta data?
- Main Menu Hover is Always White