How to show the current template WordPress is using

If you do any WordPress theme development you will need to edit the page templates very often. It’s easy to forget what template is currently in use as you’re staring at the page. A quick way to find out which one is being used is to add the following code to your functions.php file and header.php or footer.php

Add this code to functions.php file

Thanks to WordPress Stack Exchange for this snippet of code – Link

// Display Current Template In Use
add_filter( 'template_include', 'var_template_include', 1000 );
function var_template_include( $t ){
    $GLOBALS['current_theme_template'] = basename($t);
    return $t;

function get_current_template( $echo = false ) {
    if( !isset( $GLOBALS['current_theme_template'] ) )
        return false;
    if( $echo )
        echo $GLOBALS['current_theme_template'];
        return $GLOBALS['current_theme_template'];

Add this code to the header.php or footer.php file

// If the current user can manage options(ie. an admin)
if( current_user_can( 'manage_options' ) ) 
    // Print the saved global 
    printf( '<div class="current-template"><strong>Current template:</strong> %s</div>', get_current_template() ); 

Extra CSS styling

I added the class “current-template” to the div so I can style it easily in the theme.

.current-template {
	background: white;
	color: red;
	padding: 2px 5px;
	position: fixed;
	bottom: 5px;
	right: 5px;
	box-shadow: 0 0 2px #333;
	opacity: .2;
	transition: all .1s ease;
.current-template:hover {
	opacity: 1.0;
	transition: all .1s ease;
	padding: 8px;