WordPress already applies the CSS class current-page-ancestor
to the <li>
if it is a link to a Page that is a parent (or higher) of the current Page. This follows the Page structure, not the menu structure. If this is not fit for your situation, could you edit your question to make it more clear how it differs?
Related Posts:
- 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
- Directing a page to a default subpage
- 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
- Hide pages depending on role
- Get parent page/menu id of current post
- Change menu items URL
- Making WordPress’ page and menus visible only for logged in users, checking session variables
- Different side menu on each page
- WordPress – site with 2 stylesheets and more…
- Remove Page Name From WordPress Menu
- Hiding Menu From Specific Pages
- 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?
- Auto add pages to primary menu with functions.php
- Does loading of sub pages in menu cause load to the server?
- WordPress menu permalink redirects to wrong page
- Link to Homepage in Menu
- Schedule Page to Menu [duplicate]
- Add class active to static menu
- wp_list_pages() but only show children on the branch you are on
- Check if Page Already Exists in Menu
- 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
- Ad custom admin page like WordPress customizer [closed]
- Displaying different page links on different pages
- 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
- How can I switch pages?
- Prevent menu from loading in a page template [duplicate]
- How to create a menu item which is not a page
- 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?
- How to Structure Pages and Subpages
- Three menus – parent / child / sibling
- 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
- Get parents child pages
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- wp_nav_menu without menu or theme_location specified
- I can’t add more pages to menu – menu delete pages
- wp_list_pages Hierarchical Help
- Parent Page > Child Page Menu
- Making pages in a menu appear conditionally
- Add pages content to startpage through custom menu
- add_menu_page does not render the expected result
- Main menu navigation links and new pages
- Page header menu links change
- Catagorized hierarchy menu for PAGES!
- How to show pages in menu without link
- Add a menu metabox to post edit page
- Setting or plugin for showing submenus horizontally under the main menu, and keep them after selection
- Page dependent sub-menu?
- Add prefix to url, but products not showing in page SHOP
- adding pages in underscores.me theme
- How to get the Page Name of the current page?
- 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?
- WP pages content is missing in frontend
- Unable to remove page from primary menu
- how to create pages and link them to a menu
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- Any simple way to show 10 previous pages by id to current page in links as a menu
- How to add class and span to
- Specific Page that convert Hyperlink to anchor in nav menu
- WordPress – Apperance > Menu
- Creating and populating custom nav menu (menu-item-position not working)
- How to make a page to not appear in the menu when created?
- Two pages named the same thing, on a different level but conflicting url paths in menus and direct links
- Site with all content on the front page
- Adding Pages to Menus – No Page Hierarchy in Backend [duplicate]
- Some informations about the use of statics pages in WordPress
- How can I make this process automatic?
- my theme automatically adds new pages to menu
- how can i get the page_ID in nav li [closed]
- How does WP knows which template to use for a page
- Problems with draft website pages
- Add a page to a subscribers account
- Control page access based on User Meta data?
- Add custom attribute to menu item link using Filter
- Getting stripos error when trying to add menu classes
- Show Menu from one WordPress install in another WordPress install
- Orderby menu_order not working; menu is sorted on publish date
- Menu page with three columns
- Bootstrap Theme Migrated to WordPress
- I can´t make the menu unclickable in an easy way
- Hamburger Navigation Menu
- How do I get the menu items based on name or ID?