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…
- wp_nav_menu: show menu only if one exists, otherwise show nothing
- Add child pages automatically to nav menu
- Automatically remove trashed pages from nav menu
- How to move parent li to end of child ul
- Directing a page to a default subpage
- How to apply a class to the second word in menu list item?
- Can you have different menus and theme on a per-page basis?
- List children of second level sub page
- How to make pages metabox display all hierarchy in menu admin?
- How to get current page menu item name instead of full menu item list
- Override custom menu widget
- Hide pages depending on role
- Get parent page/menu id of current post
- Styling child custom menu pages
- Change menu items URL
- When at / ( or “home”) my menu doesn’t get a current-menu-item class
- 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]
- Different side menu on each page
- Custom Post type menu highlighted in the archive/post
- Add nav menu CSS class to body
- Remove Page Name From WordPress Menu
- Hiding Menu From Specific Pages
- Getting post content within wp_nav_walker
- Vertical Sidebar Menu Parent and Child not displaying correctly [closed]
- wp_list_pages sort order is different for different languages [closed]
- list pages only from master parent
- How to insert custom code into wp_nav_menu structure?
- wp_list_pages: only show subpages on the parent page?
- remove everything from wp_nav_menu
- Editing WordPress Nav Menu Walker
- 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?
- WordPress Admin Bar Covering & Overlapping Fixed Menu Header [closed]
- WordPress menu permalink redirects to wrong page
- How to add class to and childs of sidebar widget – WordPress
- Link to Homepage in Menu
- Schedule Page to Menu [duplicate]
- Add CSS to head depending on nav menu walker
- Grey out nav buttons unless is_user_logged_in()
- Add a class at specific element in custom Menu Walker
- wp_list_pages() but only show children on the branch you are on
- 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
- Check if Page Already Exists in Menu
- Side Menu Icon Expandable
- wp_nav_menu not working [closed]
- create a 2 row menu in wordpress
- Making nav menu sticky and transparent
- current-menu-item class in CSS
- 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
- Displaying different page links on different pages
- Create custom page and add it in nav menu by code
- Switch from hover to click on Twenty Twelve Menu
- Does is_child() exist in wp 3.5.1?
- How to style a specific nav menu item?
- wp_list_pages sort order by custom nav menu order
- How to highlight 1st level menu item based on actual page
- How can I switch pages?
- Prevent menu from loading in a page template [duplicate]
- How Do I Add Images To Main Navigation Menu
- Excluding a media query from specific pages
- 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]
- How to change the color of a menu item [closed]
- display menu as table layout
- Highlight parent if item from submenu is active
- WordPress + Bootstrap [closed]
- How to create a menu item which is not a page
- styling wp_nav_menu – horizontal, sub-menu drop downs
- How can I make a menu link visible only to admins (without plugins)?
- How to add a page to header that is outside of WordPress?
- Menu Arrow for Child Element
- How to Structure Pages and Subpages
- Highlighting top level link when viewing one of it’s sub-pages, which are not linked in the menu
- Three menus – parent / child / sibling
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Trouble hiding menu on single page
- change hover color of specific menu link [closed]
- How to add css to single navigation text? [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?
- Disable parent in wp_list_pages – WordPress
- Page appears after de registering from menu
- Full screen nav menu block with avada theme
- How do I change/remove styling (top border) on main menu for active page and hovering (Avada Theme)
- Hide pages from the main menu