Add is_child() Functionality to WordPress

A handy WordPress function to allow you to filter by child pages for great functionality.  Please see reference and author here. Function and simple example usage. Please see website of Kevin Leary for greater functionality and more complex usage.

<?php  
function is_child( $parent = '' ) {     
     global $post;      
     $parent_obj = get_page( $post->post_parent, ARRAY_A );     
     $parent = (string) $parent;     
     $parent_array = (array) $parent;      

     if ( in_array( (string) $parent_obj['ID'], $parent_array ) ) {         
          return true;     

     } elseif ( in_array( (string) $parent_obj['post_title'], $parent_array ) ) {         
          return true;         

     } elseif ( in_array( (string) $parent_obj['post_name'], $parent_array ) ) {         

          return true;     

     } else {         

          return false;     

     }  

}   

if ( is_child(221) );  ?>

 

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.