# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: developer, templates, admin-bar, debugging
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/show-template-in-admin-bar/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show the Current Template in the Admin Bar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
