Last Updated: February 25, 2016
·
3.431K
· dreszczyk

[Wordpress] How to check if page is a child?

Paste this into your functions.php:

function is_child($pageid) { 
 global $post; 
 if( is_page() && ($post->post_parent == $pageid) ) {
 return true; // is child
 } else { 
 return false; // not child
 }
}

In your template use if like this:

if (is_child(X)) {
 //do somthing
}

1 Response
Add your response

Nice function, just for keeping it explicit would ischildof be a more descriptive name?

over 1 year ago ·