Skip to content

Instantly share code, notes, and snippets.

@gonssal
Created September 22, 2019 23:26
Show Gist options
  • Save gonssal/64dfcff57884ae9123adb2cfcb90484b to your computer and use it in GitHub Desktop.
Save gonssal/64dfcff57884ae9123adb2cfcb90484b to your computer and use it in GitHub Desktop.
WordPress theme debug template name
<?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