Use get_ancestors
to get the page parent, then check against that value instead of checking against the name.
$ancestors = array();
$ancestors = get_ancestors($post->ID,'page');
$parent = (!empty($ancestors)) ? array_pop($ancestors) : $post->ID;
if (!empty($parent)) {
switch ($parent){
case 1 :
// menu for parent page ID 1
break;
case 2 :
// menu for parent page ID 2
break;
}
}
And so on. Your numbers will need to match against the IDs of the parent pages.
Related Posts:
- Adding first / last CSS classes to menus
- Second Navigation inside header
- wp nav menu: add attributes to menu items [duplicate]
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Add class to DIV depending on page loaded
- Menu Custom Data Attributes
- How to modify mobile nav menu text in theme
- Extend Menu Walker Output
- wp nav menu: show submenu below li item
- Styling an “active” link outside of WordPress default menu
- how to changes mobile menu toggle breakpoint in WordPress
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- How to let mobile navigation menu close when link is clicked?
- Bring Font Awesome icons inside menu A tags
- Display specific main Sub Nav on Woocommerce product pages
- Widget Logic – display on page and all child
- How limit the width of a fixed menu-bar on scroll?
- WP_Nav Highlight Parent Issue
- How to change the menu color
- Load slideshow.css file only if Slideshow is checked / on
- WP Walker using custom css classes
- Parent theme CSS overriding child CSS rules
- how to remove metadata from the posts of my blog?
- How to style options page in dashboard?
- Change list item content in menu navigation to add a child element with specific class
- Theme Options Page – User Updates Logo
- how could I load a different template part by page
- How to use my style.css file outside of wordpress subdomain?
- Dynamic Stylesheet loads but doesn’t finish
- How to add date to navigation bar
- Menu Limitations
- How can I Add a variable PHP in the Menu Nav
- Selectbox in admin panel function linking to CSS
- Where to place PHP code that inserts (or doesn’t insert) menu item?
- Can I install/embed WordPress on a ‘single page’?
- Using if/else statements with output from theme options
- Is there CSS to expand the gallery limit on Index Pages?
- Adding an Avatar to the Top Nav Bar
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- How to design a table based on css values set from admin/dashboard
- Remove metabox from WordPress menu editor page?
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- How to add an arrow to menu items has submenus
- wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
- WordPress, AJAX and pre_get_posts using conditional tags
- Incorrect MIME type for assets with Valet
- How to display pictures from database?
- How to add condition in wordpress loop? [closed]
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Title Case WordPress Menu Items
- Customize position of social icons in upme plugin [closed]
- Delete mobile menu button [closed]
- Best way to schedule daily change in CSS parameter
- Css loads very slow [closed]
- Gravity form built in Captcha
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- How does wp_enqueue_scripts work?
- Different post styles depending on category
- How create a Shortcode with hover and complex options
- WordPress Multiple Navigation bars
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Trying to store submenu items to render out after main menu
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- How to change menu order item
- two columns of posts on homepage, one of them “favorites”
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Whats the proper way to use a php stylesheet in a wordpress theme? [duplicate]
- custom css for admin only
- Custom Menus: dynamic highlighting problem with custom home link
- responsive.css in the WordPress should be prioritized
- How do I add a custom css to all posts without affecting homepage css? [closed]
- get_the_title() gets printed out twice
- If tag equals then show else show
- Redirect to another page using contact form 7? [closed]
- Which is the correct way to conditionally enqueue a CSS file?
- Custom Background by Page IDs
- proper way to add css using functions.php?
- WordPress style.css not updating, only after theme reload
- Adding logo to WordPress header
- Thumbnails appear to be zoomed
- Use PHP in stylesheet to specify a background image based on Category ID
- Add item to top of menu using a filter in functions.php
- Automatically set all tags to have a height of 0 if there is no content inside the tag [closed]
- height should be set to auto to avoid pixelation in the post thumbnail function
- Odd / Even posts add class minus first post
- Change CSS based on is_user_logged_in
- Adding PHP in the menu
- Two menus show up
- RTL Stylesheet Confusion with WordPress
- Correct way to enqueue page specific CSS file
- Wrapping a Sidebar within
- Add Codepen animation as Preloader to WordPress
- Register a menu – Error Header
- WordPress wp_add_inline_style unable to give hex colors?
- How to style one item from main navigation?
- Reduce size of responsive title