Skip to content

Instantly share code, notes, and snippets.

@RealShermanB
Last active December 20, 2015 18:39
Show Gist options
  • Save RealShermanB/6177356 to your computer and use it in GitHub Desktop.
Save RealShermanB/6177356 to your computer and use it in GitHub Desktop.
I seem to need this code all the time. It creates a function for displaying which wordpress theme template is currently being used.
<?php
/**
* Add to your functions.php
* from here: http://wordpress.stackexchange.com/questions/10537/get-name-of-the-current-template-file
*/
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'];
else
return $GLOBALS['current_theme_template'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment