Which template — an essential theme development function

So you’re developing a theme for a new project that you’re working on. It has lots of queries, a few different content types, a custom taxonomy or two, etc… It can often be difficult to determine what template is generating the page you’re looking at on the screen. Is this page using page.php, page-{slug}.php, single.php, taxonomy-{taxonomy}-{slug}.php ? You get the idea.

I use this function on every single site I develop, but don’t often see it being used out there in the wild. Just pop this function into your functions.php file and it will output the current template file being used to the bottom of your page:

 * Print out the current template file to the footer.
 * Remove before launch. 

function waterstreetgm_which_template() {
	if ( is_super_admin() ) {
		global $template;
		echo '<strong>Template file:</strong>';
		print_r( $template );
add_action( 'wp_footer', 'waterstreetgm_which_template' );