Created
December 19, 2017 08:23
-
-
Save yuriitaran/a20d77e658fe96498153e6f113269e8b to your computer and use it in GitHub Desktop.
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
// 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