Whenever I’m working on a new WordPress theme, especially one that uses different templates for Custom Post Types, archives, tags or any other string of possible data types, there always comes a time when I’m just not certain exactly which template WordPress is displaying.
If you aren’t sure how the WordPress theme hierarchy works, this graphic shows the exact flow on how WordPress chooses which template file to use for a given page. But, when you are making changes to CPT slugs, page names, taxonomies and the like, in order to know exactly which file is actually being used on the page you’re viewing, you’re going to need a little more assistance. That’s where this piece of code comes in to play.
Open up your theme’s functions.php file and add the following:
1 2 3 4 5 6 | add_action('wp_head', 'show_template'); function show_template() { global $template; print_r($template); } |
Save the file and now when you view your site in a browser, you’ll see something like this:

Just below the admin bar and right above the beginning of your site you’ll see the directory path and file name being used on the page you’re viewing. No more guessing!
It should go without saying, but I’ll say it anyway… Unless you want this showing up on your live site, please comment out this code before pushing your theme live.























