Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Created April 23, 2014 15:16
Show Gist options
  • Save ivandoric/11219508 to your computer and use it in GitHub Desktop.
Save ivandoric/11219508 to your computer and use it in GitHub Desktop.
wordpress: is_tree function - Check if on certain page or on page children function
<?php
function is_tree($pid) {
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;
else
return false;
};
/* Use like this */
if(is_tree(PAGE_ID)){
// something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment