Skip to content

Instantly share code, notes, and snippets.

@jesders
Forked from ivandoric/gist:11219508
Created April 15, 2020 12:21
Show Gist options
  • Save jesders/a8202a34e2271956da402ad34f0e9e22 to your computer and use it in GitHub Desktop.
Save jesders/a8202a34e2271956da402ad34f0e9e22 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