Put this function into your theme’s function.php
file.
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post;
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
}
if(is_page()&&(is_page($pid))) { return true; /*we're at the page or at a sub page*/ }
else { return false; /*we're elsewhere*/ }
}
Then wrap your code in:
<?php
// put the parent id or in this case, South America's id as the parent-id
if(is_tree('parent-id')) {
// output your menu
}
?>
Related Posts:
- Automatically Add New Tags to Sub-menu
- Setting color of specific menu items depending on page or post tag
- How do I make it so a post only shows in its category archive but not the home page?
- extra tag is added in wp_nav_menu
- Add data-icon input to WordPress custom menu links
- Registering menu with ‘Automatically add new top-level pages to this menu’ selected
- Whats the difference between current_page_item and current-menu-item
- Menu limit, cannot add new menu items
- Remove Pagination in Appearance -> Menus -> Categories
- How to get a separate child menu?
- wordpress nav menu using twitter bootstrap
- Add a logout menu link [duplicate]
- How to open modal window when clicking a WP menu link?
- How to get current page menu item name instead of full menu item list
- Styling child custom menu pages
- change front end menu depending on user login
- wp_nav_menu show 1 item only
- Sub-Pages only of menu items in current branch using a custom menu
- Hide and show menu subpages
- Mobile menu works on local XAMPP, but not on GoDaddy [closed]
- wp_nav_menu and fallback
- list pages only from master parent
- WordPress cache a menu with Transient API
- Counting top level items in a custom menu walker
- Wp menu add page link as custom empty link
- how do I add “home” menu item conditionally to custom menus?
- How to add div to top menu item
- wp_nav_menu including Skype URL
- Inserting additional into menu item text
- Missing Menus Structure
- Why is my menu not ordered properly?
- How to add class to and childs of sidebar widget – WordPress
- CSS for Created Menu “Active Selected” not working, everything else is!
- header menu structure: cannot add additional menu items without alignment issues
- My menu bar dissapeared with autooptimize [closed]
- Menu in left side don’t appears with dropdown
- WP custom nav menu problem
- Show WordPress Menu On External Site
- Create custom page and add it in nav menu by code
- Two-tone menu items
- How to highlight 1st level menu item based on actual page
- Submenu items not showing anymore on the navigation
- superfish.js seems it is not working properly after wordpress upgarde to 4.6.1
- How to add an attribute data-slug = “$specfic_page_slug” in WordPress menu item?
- Hide a menu on posts
- How to add a page to header that is outside of WordPress?
- Get current menu item label for specific parent menu [closed]
- Can’t create a SubMenu
- Having trouble adding CSS class through menu to link
- Mobile screen does not display Primary navbar…just a three line icon [closed]
- How do I enable “metaboxes” by default in menu editor?
- The cart, checkout, and shop links not getting removed
- How to pass menu slug as a variable to wp_nav_menu?
- New Menu Item Type Meta Box
- Using Different wp_nav_menu theme_location based on page id (or a parent id)
- Display Menu Navigation Label
- Menu is not displaying on the site navigation [closed]
- Dynamically get the meta key value of a menu item based on it’s post ID
- Does this function wp_get_nav_menu_object check if a nav menu exists or is supported?
- Updated WordPress, now Navigation is Messed Up
- wp_nav_menu removing containing UL with ‘items_wrap’ => ‘%3$s’ not working
- How to show only current item children using wp_nav_menu?
- New menu is not showing in api response
- Newly created header is not visible on website
- Copied site has wrong menu URL behaviour
- Removing wp admin menu item on top bar of admin backend
- Nav_walker add id to dropdown ul
- Navbar is hidden behind carousel when using wp-boostrap-navwalker
- WordPress nav-menus not finding page
- Primary menu items are dissapearing
- Active Current Menu – Adding class to child theme
- WPML CMS Nav and Custom Nav_Walker Undefined Property Notices [closed]
- Add data-track to links in menu
- Is it possible to seperate wordpress menu by different div?
- How to add odd and even classes to all nav links through walker?
- Output sort number in wp menu list item?
- Check in walker if current page is descendant
- Add a non-dynamic phrase/character after a page title?
- Primery Menu Configuration problem
- how to display wordpress navbar with top menu outside wordpress system
- Active page link not getting class assigned
- Removing menu item doesn’t get removed on edit post
- Remove from wp_nav_menu() wordpress
- How do I add a link to the menu that has a charector (?) in it?
- Problem with custom menus
- Styling Active Links Within WordPress
- Make title bar collapse when scrolling
- how to show a custom taxonomy as dropdown in wordpress?
- Problem to asign class to with wp_nav_menu()
- Changing color of specific tab of top menu
- how to add fa fa icons customize menu using wp_nav_menu function?
- How can I structure my pseudo footer nav code with wordpress codex code?
- What is the best way to incorporate responsive dropdown navigation menu into custom theme?
- how to add permalink/slug to wordpress custom link menu item
- Using walker to display all menu branches at once?
- How to add a class directly on a unordered list element that is a primary navigation
- Submenu items not working anymore
- Icon not shown in Dropdown menus in Twenty Seventeen Theme
- How to change WP menu item type?
- How to change mobile menu (toggle) icon in WordPress – Full Site Editing?