I've taken over the maintainance of a large WP-MS powered site. The site has ~200 templates, many page specific, and with no standard naming procedure.

It would save a lot of time if while surfing around the site I can see the template names which make up the current page. Is this possible? I've looked at the debug plugins for WordPress, but they appear geared towards variables and SQL queries, not templates.

4 Answers 4


this is also a quick way;


<?php print_r( debug_backtrace() ) ?>


paste it just before the closing tag

  • 2
    In testing this is more reliable than @kaiser's code, as it works on pages and posts; but it's also a lot more confusing to read :)
    – PeterB
    Oct 25, 2011 at 7:40

The following functions do 3 things:

  • Show the template hierarchy for the current requesst
  • Show the theme in use (2 ways to acchive this shown)
  • Show the current template in use for the request *)

*) Attach it to the content filter. You may need to play with the conditional or capability depending on your role. So far I don't know a solution to show the page template for archives and similar list view requests.

// That's not that easy to read:
var_dump( get_required_files() );

 * 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' ) )

        // 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' );

 * Show template on singular views attached to the end of the content for admins
 * @return $content
function wpse31909_template_to_content( $content )
        // Display standard content for non-admin users and not single post/page/cpt/attachment view.
        if ( ! current_user_can( 'manage_options' ) && ! is_singular() )
            return $content;

        $content .= '<pre>';
            // Show current template in use: Must be in the loop to get the global $post
           $content .= var_export( get_post_meta( $GLOBALS['post']->ID, '_wp_page_template' ), true );
        $content .= '</pre>';

        return $content;
add_filter( 'the_content', 'wpse31909_template_to_content' );
  • Maybe it might work if you attach the second function to the the_excerpt filter too. Guess it would then also show up on list views. @All Feel free to edit & extend this answer.
    – kaiser
    Oct 24, 2011 at 12:10
  • 1
    There's a typo with the variable in the first var_dump.
    – t31os
    Oct 24, 2011 at 13:49
  • @t31os Don't want to fix it? Brings +2 rep points on every upvote. Thanks anyway :)
    – kaiser
    Oct 24, 2011 at 14:00
  • Not around so much, was more of a drive-by observation.. ;)
    – t31os
    Oct 25, 2011 at 10:21
  • @t31os A pretty good one. Glad it wasn't "fitler" instead of "filter" ;)
    – kaiser
    Oct 25, 2011 at 14:05

I use this to simply print the template filename at the top of the page for debugging purposes.

// For debugging - show template file
add_action('wp_head', 'show_template');
function show_template() {
    global $template;

While not directly an answer to the question at hand, it should probably also be noted here that by default WordPress adds a class name to the <body> tag for custom page templates. So for instance, if you are viewing a page that has a custom page template, and the template's filename is custom.php, then a class name of page-template-custom will be added to the <body> tag.

Documentation on this feature can be found here: https://codex.wordpress.org/Function_Reference/body_class#Page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.