-
-
Save paulgosnell/9092267 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Is the current page a descendent of page identified by the path (not slug). | |
* A page is not a descendent of itself! | |
* @link http://wordpress.stackexchange.com/questions/101213/does-is-child-exist-in-wp-3-5-1 | |
* @param string $page_path The path of the page, e.g. mypage/mysubpage | |
* @return boolean True if current page is a descednent of specified $page_path. False otherwise. | |
*/ | |
function is_descendent_of( $page_path ){ | |
if( !is_page() ){ | |
return false; | |
} | |
$ancestors = get_post_ancestors( get_queried_object_id() ); | |
$page = get_page_by_path( $page_path ); | |
if( $page ) | |
return in_array( $page->ID, $ancestors ); | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment