Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/8bb719130017f7d9d0ea to your computer and use it in GitHub Desktop.
Save jaredatch/8bb719130017f7d9d0ea to your computer and use it in GitHub Desktop.
Check for page template deep
<?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