Skip to content

Instantly share code, notes, and snippets.

@tmort
Last active February 9, 2016 11:58
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 tmort/259d0dbab13903cafb1c to your computer and use it in GitHub Desktop.
Save tmort/259d0dbab13903cafb1c to your computer and use it in GitHub Desktop.
WordPress - Find my Template Files
// You will need to uncomment the following line
//define('WP_LOCAL_DEV', true);
add_action ('wp_footer', 'view_template_files');
if (! function_exists ('view_template_files')):
function view_template_files () {
if (defined ('WP_LOCAL_DEV') && WP_LOCAL_DEV) {
global $template;
$template_name = basename($template, '.php');
$template_dir = basename(dirname($template));
$included_files = get_included_files();
$stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() );
$template_dir_path = str_replace( '\\', '/', get_template_directory() );
foreach ( $included_files as $key => $path ) {
$path = str_replace( '\\', '/', $path );
if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir_path ) )
unset( $included_files[$key] );
}
echo '<code style="height:90%;overflow-y:scroll;position: fixed; top:0; right:10px; z-index: 9999; padding: 10px; color:#000000;background:rgba(255,255,255,.5)"> ';
echo "Theme: ".$template_dir."<br />";
echo "Template: ".$template_name.".php<br />";
echo "Included Files:<br />";
foreach($included_files as $file){
echo basename($file)."<br>";
}
echo "</ code> \n";
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment