Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

this is also a quick way;

<!--

<? print_r( debug_backtrace() ) ?>

-->

paste it just before the closing tag

share|improve this answer
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 '11 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' ) )
            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' );


/**
 * 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' );
share|improve this answer
    
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 '11 at 12:10
1  
There's a typo with the variable in the first var_dump. –  t31os Oct 24 '11 at 13:49
    
@t31os Don't want to fix it? Brings +2 rep points on every upvote. Thanks anyway :) –  kaiser Oct 24 '11 at 14:00
    
Not around so much, was more of a drive-by observation.. ;) –  t31os Oct 25 '11 at 10:21
    
@t31os A pretty good one. Glad it wasn't "fitler" instead of "filter" ;) –  kaiser Oct 25 '11 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;
    print_r($template);
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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