Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriitaran/a20d77e658fe96498153e6f113269e8b to your computer and use it in GitHub Desktop.
Save yuriitaran/a20d77e658fe96498153e6f113269e8b to your computer and use it in GitHub Desktop.
// in footer.php or header.php
<div><strong>Current template:</strong> <?php get_current_template( true ); ?></div>
// in functions.php
/**
* Define current template file
*
* Create a global variable with the name of the current
* theme template file being used.
*
* @param $template The full path to the current template
*/
function define_current_template( $template ) {
$GLOBALS['current_theme_template'] = basename($template);
return $template;
}
add_action('template_include', 'define_current_template', 1000);
/**
* Get Current Theme Template Filename
*
* Get's the name of the current theme template file being used
*
* @global $current_theme_template Defined using define_current_template()
* @param $echo Defines whether to return or print the template filename
* @return The name of the template filename, including .php
*/
function get_current_template( $echo = false ) {
if ( !isset( $GLOBALS['current_theme_template'] ) ) {
trigger_error( '$current_theme_template has not been defined yet', E_USER_WARNING );
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