Created
November 11, 2015 11:56
-
-
Save cadic/cbdb96446a6ed06e2598 to your computer and use it in GitHub Desktop.
Wordpress: function returns true if current page is child of specified page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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