is_child() Conditional Function for WordPress
by Bandicoot Marketing on | Posted in Tutorials | 7 comments
I wrote a little function a while back to Check if a Page is a Child of Another Page in WordPress called is_child()
. It used the page ID to return a true or false value dependent on if the current page was a child of the parent page specified. I have recently made a little change so that the function could now accept either a page ID or slug.
Here it is again with the changes:
function is_child($page_id_or_slug) { global $post; if(!is_int($page_id_or_slug)) { $page = get_page_by_path($page_id_or_slug); $page_id_or_slug = $page->ID; } if(is_page() && $post->post_parent == $page_id_or_slug ) { return true; } else { return false; } }
The modification was inspired by Helpful Page Functions for WordPress.
7 comments for “is_child() Conditional Function for WordPress”