Show the Current Template in the Admin Bar
Displays the theme template file (and block template, on block themes) used for the current page in the admin bar, for administrators only.
Opens WPIDE on
Code
add_filter( 'template_include', function ( $template ) {
$GLOBALS['wpide_current_template'] = $template;
return $template;
}, 9999 );
add_action( 'admin_bar_menu', function ( $admin_bar ) {
if ( is_admin() || ! current_user_can( 'manage_options' ) || empty( $GLOBALS['wpide_current_template'] ) ) {
return;
}
$template = wp_normalize_path( $GLOBALS['wpide_current_template'] );
$label = str_replace( wp_normalize_path( get_theme_root() ) . '/', '', $template );
if ( ! empty( $GLOBALS['_wp_current_template_id'] ) ) {
$label = $GLOBALS['_wp_current_template_id'];
}
$admin_bar->add_node( array(
'id' => 'wpide-current-template',
'parent' => 'top-secondary',
'title' => 'Template: ' . esc_html( $label ),
) );
}, 999 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.