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
- start_lvl Ignored in Custom walker_nav_menu
- wp_delete_auto_drafts() deletes links in menus
- Check if a menu is empty?
- the_author_posts_link css class
- Walker class: Problems with understanding how walk() method can be called without error
- How can I access the “description” of a menu item?
- wp enqueue style and style sheet depth
- CSS saved & enqueued, but wordpress doesn’t load css text, only file
- Is it possible to use the featured image of a page as a css background without inlining?
- How to display a value from a radio button in the options menu in wordpress
- How should I best target dynamically served content?
- Using is_page() in functions.php not working at all
- How to scale image with equal width and height without distortion?
- items_wrap not working
- php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)
- How to enqueue CSS and JS only on specific template?
- Have CSS Class Added with `is_page()` WP function
- An unwanted inline style is added to my body tag
- Problem adding class to body_class
- Run a filter when a walker runs
- How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts
- Input type search in Menu
- Title Case WordPress Menu Items
- Gravity form built in Captcha
- How does wp_enqueue_scripts work?
- Trying to store submenu items to render out after main menu
- Whats the proper way to use a php stylesheet in a wordpress theme? [duplicate]
- get_the_title() gets printed out twice
- Thumbnails appear to be zoomed
- height should be set to auto to avoid pixelation in the post thumbnail function
- Add Codepen animation as Preloader to WordPress
- Reduce size of responsive title
- Show About and Contact Us page when they’re clicked in the top menu.
- Conditional statement for dates
- Clickable image link sends people to wrong URL
- Creating a mobile site by adding a new class to the body tag from functions.php
- Display an image based on field value
- Get css class of menu item in custom menu structure
- Assign Custom classes to every Excerpt
- Show login greeting above sub-menu links?
- Why can’t I add a custom image in my navigation?
- Horizontal drop down category with hover effect working
- Create Columns with Custom Walker and CSS Classes
- Background image no longer fits to screen now that project is in php files
- Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
- Why would the child theme load in the Customize preview, but not on the site itself?
- echo cutom css code to WordPress page template file ? is this safe?
- Trying to generate a CSS file in wordpress uploads folder
- WP Website is shown in HTML
- How to put 2 php codes in functions.php without site crashing
- I cannot find the wordpress.scss file that my live site is pulling from
- I got big white screen when i attach main style sheet of Html in functions.php
- wp_get_nav_menu_items() with ACF
- How to switch between two primary menus (programatically0
- Redirect User when they click Menu Option
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- Add a default style if no Featured image is selected
- How to give custom roles the capability to edit one Menu instead of every Menu
- Primary navigation menu with timed items from custom post type
- Styling a specific post after hovering over it
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- CSS loading as empty file in Custom Theme
- Where to find the html for WordPress site? [closed]
- Two theme locations for two menus, but only one is showing up
- How to remove image on single product and get product to span page?
- widget: input the px value from user and use it as inline style in widget function
- Contact form field in wordpress menu
- How to call a certain object/menubar in a PHP file
- Sidebar current menu item for parent
- How Can I Center the Logo in the Navigation Menu? [closed]
- Nav Menu Display
- Conditional in foreach loop is outputting content twice
- Advanced custom fields Repeater conditional statement not working [closed]
- How to create and add js and css file when server is not on my PC?
- which php or css file has generated an inline style in WordPress that overwrites my css
- Header location [closed]
- advanced custom fields: repeater field within conditional statement [closed]
- inner-wrap div pushing custom table far down on page
- Custom nav with bootstrap dropdown