Created
May 29, 2013 23:26
-
-
Save stephenharris/5674643 to your computer and use it in GitHub Desktop.
Check if current page is a descendant of the specified one.
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
How can this be modified to check the slug?