Skip to content

Instantly share code, notes, and snippets.

@cadic
Created November 11, 2015 11:56
Show Gist options
  • Save cadic/cbdb96446a6ed06e2598 to your computer and use it in GitHub Desktop.
Save cadic/cbdb96446a6ed06e2598 to your computer and use it in GitHub Desktop.
Wordpress: function returns true if current page is child of specified page
<?php
function ml_is_child_of( $parent_id, $post_id = null, $post_type = 'page' )
{
if ( !is_page() )
return false;
$post_id = ( $post_id ) ? $post_id : get_the_ID();
$ancestors = get_ancestors( $post_id, $post_type );
return in_array( $parent_id, $ancestors );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment