Skip to content

Instantly share code, notes, and snippets.

@lightyoruichi
Created February 9, 2012 10:22
Show Gist options
  • Save lightyoruichi/1779093 to your computer and use it in GitHub Desktop.
Save lightyoruichi/1779093 to your computer and use it in GitHub Desktop.
See which file WP is loading for templates
// 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 ;
}
<?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