Skip to content

Instantly share code, notes, and snippets.

@paulgosnell
Forked from stephenharris/is-descendent-of.php
Created February 19, 2014 13:44
Show Gist options
  • Save paulgosnell/9092267 to your computer and use it in GitHub Desktop.
Save paulgosnell/9092267 to your computer and use it in GitHub Desktop.
<?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