Last active
December 20, 2015 18:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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