Tell me more ×
WordPress Answers 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
I inspect the html and find an identified tag or something unique. – Naoise Golden Dec 27 '11 at 18:38

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

8 Answers

up vote 5 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

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

share|improve this answer
That is a great plugin. Just installed it. Thanks for the awareness. – Jason Apr 1 at 0:24

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

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

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

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

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

It's easy. You just need to follow this tutorial

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.