Skip to content

Instantly share code, notes, and snippets.

@Kenshino
Created September 29, 2014 16:23
Show Gist options
  • Save Kenshino/1f3d7943a1bc46ead5f4 to your computer and use it in GitHub Desktop.
Save Kenshino/1f3d7943a1bc46ead5f4 to your computer and use it in GitHub Desktop.
page sub menu functions
function get_top_parent_page_id() {
global $post;
// Check if page is a child page (any level)
if ($post->ancestors) {
// Grab the ID of top-level page from the tree
return end($post->ancestors);
} else {
// Page is the top level, so use it's own id
return $post->ID;
}
}
function is_subpage() {
global $post; // load details about this page
if ( is_page() && $post->post_parent ) { // test to see if the page has a parent
return $post->post_parent; // return the ID of the parent post
} else { // there is no parent so ...
return false; // ... the answer to the question is false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment