How to Print Active WordPress Template File

WordPressI’ve needed to print the currently active WordPress template file and have forgotten it enough times now to finally document it as a post. During development, there’s usually always a time when you’ll want to detect the the template file that’s being called.

I use the following code in my theme/child theme’s header.php file and print it to the screen:

/* show me what the body class will look like */
echo body_class() . "\n";
/* make sure i've got $template */
global $template;
/* print the active template path and filename */

That’s it. That’s how I print the currently active template file in use for WordPress.

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

2 Responses to “How to Print Active WordPress Template File”

Leave a Reply