Last active
August 29, 2015 14:03
-
-
Save azeemhassni/ba075aaf70766d79ee23 to your computer and use it in GitHub Desktop.
WordPress get Current Template Name
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
/** | |
* @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