You could set a global variable during the template_include filter and then later check that global vairable to see which template has been included.
You naturally wouldn’t want the complete path along with the file, so i’d recommend truncating down to the filename using PHP’s basename function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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']; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.