Skip to content

Instantly share code, notes, and snippets.

@mt3o
Created December 29, 2015 15:31
Show Gist options
  • Select an option

  • Save mt3o/78d65901787888dd688c to your computer and use it in GitHub Desktop.

Select an option

Save mt3o/78d65901787888dd688c to your computer and use it in GitHub Desktop.
Print current wordpress template hierarchy.
<?php
/**
* Show template hierarchy and theme at the end of the request/page.
* @return void
*/
function wpse31909_template_info()
{
// Don't display for non-admin users
if ( ! current_user_can( 'manage_options' ) )
return;
// You have to build yourself the hierarchy here or somewhere in front of the fn
global $wp_template_hierarchy;
$content = '<pre>';
// Show template hierarchy
$content .= "TEMPLATE HIERARCHY\n==================\n";
$content .= var_export( $wp_template_hierarchy, true );
// Show current theme in use:
$content .= "\n\nCURRENT THEME\n=============\n";
$content .= var_export( get_option( 'template' ), true );
// or:
# $content .= var_export( get_template(), true );
$content .= '</pre>';
return print $content;
}
add_action( 'shutdown', 'wpse31909_template_info' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment