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.

When you activate a wordpress theme, it's always a hassle to find out which file to go to change things. Any idea how to simplify things?

But on the other hand, considering the get_template_part functionality, this may be impossible. What do you say?

share|improve this question
1  
I inspect the html and find an identified tag or something unique. –  Naoise Golden Dec 27 '11 at 18:38
    
View the source code and look for the body classes which tell you which template is used. Also gives you the i.d. –  Brad Dalton Feb 4 at 21:33
add comment

migrated from stackoverflow.com Dec 26 '11 at 2:41

This question came from our site for professional and enthusiast programmers.

8 Answers

up vote 6 down vote accepted

Hook onto template_include, set a global to note the template set by the theme then read that value back into the footer or header to see which template is being called for a given view.

I spoke about this filter hook before in get name of the current template file, but go grab a copy of that code and plonk it your theme's functions.php file.

Then open up the theme's header.php or footer.php(or wherever you like) and use something like the following to print out the current template.

<div><strong>Current template:</strong> <?php get_current_template( true ); ?></div>

If you wanted to use this on a production site and keep that info away from your non-administrator users, add a little conditional logic.

<?php 
// If the current user can manage options(ie. an admin)
if( current_user_can( 'manage_options' ) ) 
    // Print the saved global 
    printf( '<div><strong>Current template:</strong> %s</div>', get_current_template() ); 
?>

Now you can keep track of what views are using what template, whilst keeping that info away from your visitors.

share|improve this answer
    
If there is something wrong with this answer, or if anyone could provide comments on what could be done to improve this answer, have at it, drop a comment here and share your thoughts and ideas on how to make it better. –  t31os Jan 28 at 16:03
add comment

Well, if all you want is to check which template file has been used to generate the current page then you don't need to get your hands dirty with code ;)

There's this handy plugin called Debug Bar. It's a great helper in many situations including yours. You should definitely check it out - for me and many others it's a must-have companion for any WP development.

I've attached a screenshot that could make you fall in love...

enter image description here

To get the Debug Bar working, you need to enable wp_debug and wp_savequeries options. These options are in disabled state by default.

Before you make any changes though, there are a few points to keep in mind:

  • Do not do it in production environment unless the website doesn't cater to a lot of traffic.
  • Once you finish debugging, ensure to disable the options (especially the wp_savequeries option since it affects the performance) of the website.

To make the changes:

  1. Open wp_config.php file through a ftp client.
  2. Search for wp_debug option. Edit it to define( 'WP_DEBUG', false );. If the line is not present, add it to the file.
  3. Similarly, edit or add the line define( 'SAVEQUERIES', true ); to the file.
  4. Save. You are ready to debug.

More info: Codex

share|improve this answer
    
That is a great plugin. Just installed it. Thanks for the awareness. –  Jason Apr 1 '13 at 0:24
1  
@justCallMeBiru -- the Debug Bar plugin doesn't require WP_DEBUG and SAVEQUERIES, though it is enhanced by them. –  Pat J Jan 15 at 16:35
    
Running such a plugin, just for one tid bit of information creates alot of overhead imho, and thus it is why i did not suggest it in my own answer. That said, clearly people prefer this answer, i'm curious to know why though. –  t31os Jan 28 at 16:02
add comment

Add the following code right after the get_header line in each relevant template file:

<!-- <?php echo basename( __FILE__ ); ?> -->

In your browser > view source, and the template name will be displayed as a comment in your html code, e.g.

<!-- page.php -->
share|improve this answer
add comment

Easiest way I've found is to include the WordPress function on the body tag. It'll add several classes depending on which page you're viewing (home for the front, page for page, etc).

Check it out here: http://codex.wordpress.org/Function_Reference/body_class

Plus it's helpful for targeting elements with CSS on those pages.

Getting to know the Template Hierarchy (http://codex.wordpress.org/Template_Hierarchy) as David R mentioned is also a good idea.

share|improve this answer
add comment

One very simple thing I do is to insert an HTML comment identifying the template file in each relevant file of the theme, eg at the top of index.php I have

<!-- index -->

and at the top of front-page.php

<!-- front -->

But obviously that requires modifying the theme. I suspect you could add a custom function in the footer.php file or header.php which would tell you what file was being used. The above method and the reference chart http://codex.wordpress.org/Template_Hierarchy are what I tend to use.

share|improve this answer
add comment

There's another more bare-bones plugin specifically for this purpose. I'm leaning towards installing the debug bar, because those other features look useful, but this one is more basic and specifically for this purpose: http://wordpress.org/extend/plugins/what-the-file/

share|improve this answer
add comment

There is a plugin named Theme Check which does exactly this. It displays the name of the current template file in use as a HTML comment.

share|improve this answer
add comment

I use this handy function that displays the current template only for super admins:

function show_template() {
    if( is_super_admin() ){
        global $template;
        print_r($template);
    } 
}
add_action('wp_footer', 'show_template');

Hope that helps. :)

share|improve this answer
add comment

protected by Community Feb 18 at 7:26

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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