Skip to content

Instantly share code, notes, and snippets.

@azeemhassni
Last active August 29, 2015 14:03
Show Gist options
  • Save azeemhassni/ba075aaf70766d79ee23 to your computer and use it in GitHub Desktop.
Save azeemhassni/ba075aaf70766d79ee23 to your computer and use it in GitHub Desktop.
WordPress get Current Template Name
/**
* @param bool $return
* @return mixed
*/
function get_current_template_name($return = FALSE) {
$files = get_included_files();
$result = null;
$e = false;
foreach($files as $file){
$templateName = end(explode(DIRECTORY_SEPARATOR, $file));
if($e){
$result = $templateName;
break;
}
if($templateName == 'template-loader.php') {
$e = true;
}
}
if($return) return $result;
else echo $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment