Skip to content

Instantly share code, notes, and snippets.

@zumwalt
Last active October 6, 2017 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zumwalt/5217250 to your computer and use it in GitHub Desktop.
Save zumwalt/5217250 to your computer and use it in GitHub Desktop.
is_tree() for WordPress. Good times!
function is_tree( $pid ) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
if ( is_page($pid) )
return true; // we're at the page or at a sub page
$anc = get_post_ancestors( $post->ID );
foreach ( $anc as $ancestor ) {
if( is_page() && $ancestor == $pid ) {
return true;
}
}
return false; // we arn't at the page, and the page is not an ancestor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment