Figuring out templates that are being used while you are building and developing a custom WordPress website can be problematic. Using the following snippets you can quickly and easily display template name or full path to the file in your wp-admin bar.
Display Template name

To display just template name add the following to functions.php file:
function template_name() {
global $wp_admin_bar;
global $template;
if( is_user_logged_in() && current_user_can('administrator') ) {
$wp_admin_bar->add_menu( array(
'id' => 'template_name',
'parent' => 'top-secondary',
'title' => __( basename( $template ) )
) );
}
}
add_action( 'wp_before_admin_bar_render', 'template_name' );
Display full path to Template file

To display full path to the file add the following to functions.php file:
function template_name() {
global $wp_admin_bar;
global $template;
if( is_user_logged_in() && current_user_can('administrator') ) {
$wp_admin_bar->add_menu( array(
'id' => 'template_name',
'parent' => 'top-secondary',
'title' => __( $template )
) );
}
}
add_action( 'wp_before_admin_bar_render', 'template_name' );
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂