Created
September 22, 2019 23:26
-
-
Save gonssal/64dfcff57884ae9123adb2cfcb90484b to your computer and use it in GitHub Desktop.
WordPress theme debug template name
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 | |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | |
/** | |
* Adds the current template info for debugging. | |
* | |
* @param string $t The template. | |
*/ | |
function var_template_include( $t ) { | |
$GLOBALS['current_theme_template'] = basename( $t ); | |
return $t; | |
} | |
add_filter( 'template_include', 'var_template_include', 1000 ); | |
/** | |
* Prints an HTML comment with the current template's name. | |
*/ | |
function print_current_template_html_comment() { | |
if ( ! isset( $GLOBALS['current_theme_template'] ) ) { | |
return false; | |
} | |
echo '<!-- Current template: ' . $GLOBALS['current_theme_template'] . '-->'; | |
} | |
add_action( 'wp_head', 'print_current_template_html_comment' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment