[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
}
Written by Dreszczyk
Related protips
1 Response
Nice function, just for keeping it explicit would ischildof be a more descriptive name?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#