WordPress is child to selected page

This snippet of code is very useful when creating sub navigation in WordPress.
It allows you to check if a page is a child of a specific page.

Add this to your themes functions.php

/**
 * Check to see if page is a child
 * @param  int  $id id of parent
 * @return boolean
 */
function is_child($page_id) {
    global $post;
    if( is_page() && ($post->post_parent == $page_id) ) {
       return true;
    } else {
       return false;
    }
}


Liked this article? help spread the word.