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.

2 thoughts on “What Template File am I Viewing?

  1. 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 *

Ready for a refreshing experience on your next website design?