Created
February 9, 2012 10:22
-
-
Save lightyoruichi/1779093 to your computer and use it in GitHub Desktop.
See which file WP is loading for templates
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
// this can live in /themes/mytheme/functions.php, or maybe as a dev plugin? | |
function get_template_name () { | |
foreach ( debug_backtrace() as $called_file ) { | |
foreach ( $called_file as $index ) { | |
if ( !is_array($index[0]) AND strstr($index[0],'/themes/') AND !strstr($index[0],'footer.php') ) { | |
$template_file = $index[0] ; | |
} | |
} | |
} | |
$template_contents = file_get_contents($template_file) ; | |
preg_match_all("(Template Name:(.*)\n)siU",$template_contents,$template_name); | |
$template_name = trim($template_name[1][0]); | |
if ( !$template_name ) { $template_name = '(default)' ; } | |
$template_file = array_pop(explode('/themes/', basename($template_file))); | |
return $template_file . ' > '. $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
<?php if ( ! is_admin() ) { | |
echo ' | '. get_template_name(); | |
} else { | |
echo ""; | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment