Last active
August 29, 2015 14:06
-
-
Save jaredatch/8bb719130017f7d9d0ea to your computer and use it in GitHub Desktop.
Check for page template deep
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 | |
/** | |
* Checks if current or top level pages has a specific page template set. | |
* | |
* @param string | |
* @return mixed false or page id | |
*/ | |
function ja_is_page_template_deep( $template = '' ) { | |
if ( !empty( $template ) && is_page() ) { | |
$parents = get_post_ancestors( get_the_ID() ); | |
$id = ( $parents ) ? $parents[count($parents)-1]: get_the_ID(); | |
if ( !empty( $id ) && get_page_template_slug( $id ) == $template ) { | |
return $id; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment