What Template File am I Viewing?

When developing a custom theme I often find myself needing to know exactly what template WordPress is currently using to display the page. I used to simply write some dummy text directly into the file (usually ‘cha cha cha’ for some reason).

That is until I came across this plugin in the Plugin repository: What Template File Am I Viewing?. The plugin is simple and works as advertised – it simply outputs the path to the current file on the front end of the site.

Rather than install the plugin, you can simply paste the following code into your functions.php file. It will output the file information until you delete or comment out the code.

add_action('wp_head', 'show_template');
function show_template() {  
    global $template;
    echo '<span style="color: #000;">' . $template . '</span>';

There are two reasons I prefer this method over installing the plugin:

  1. I changed the plugin to enable adding a span wrapper – allowing a quick color style.
  2. I find this easier than installing and activating a plugin.


Really, really useful! Thank you so much for posting this!


I always just look at the body class. The code outputs all of the info you need to know about how you are viewing that page, including page template. SOMETIMES I will just echo it onto the page instead of as a class on an HTML element, but still works the same.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Check out our Complete Website Package

Chat with us about your project or click below to find out more!

Learn More   Chat with us

Hi. We are Spigot. Telemarketers pronounce it Spy-got.

We are a Park City, Utah based web design shop that excels at building custom websites powered by WordPress and WooCommerce. We love content - content strategy, content curation, content soup...????Have a look around the site. As you browse you'll find useful navigation links in the sidebar on the left. We hope you find them useful anyway... Please let us know what you think, shoot us a message here.