# Show the Template Parts Used on a Page

> Adds a "Template parts" menu to the front-end admin bar for administrators listing every template part loaded on the page, for both classic themes (get_template_part) and block themes.

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

## Code

```php
$wpide_template_parts = array();

add_action( 'get_template_part', function ( $slug, $name ) use ( &$wpide_template_parts ) {
    $wpide_template_parts[] = $name ? "$slug-$name" : $slug;
}, 10, 2 );

add_filter( 'render_block_core/template-part', function ( $content, $block ) use ( &$wpide_template_parts ) {
    if ( ! empty( $block['attrs']['slug'] ) ) {
        $wpide_template_parts[] = 'block: ' . $block['attrs']['slug'];
    }
    return $content;
}, 10, 2 );

// The admin bar renders in the footer, after the template parts have loaded.
add_action( 'admin_bar_menu', function ( $admin_bar ) use ( &$wpide_template_parts ) {
    if ( is_admin() || ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $parts = array_values( array_unique( $wpide_template_parts ) );

    $admin_bar->add_node( array(
        'id'    => 'wpide-template-parts',
        'title' => 'Template parts (' . count( $parts ) . ')',
    ) );

    foreach ( $parts as $i => $part ) {
        $admin_bar->add_node( array(
            'id'     => 'wpide-tpart-' . $i,
            'parent' => 'wpide-template-parts',
            'title'  => esc_html( $part ),
        ) );
    }
}, 999 );
```

## Notes

Pair it with a template viewer to see the full picture of which files build a page.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show the Template Parts Used on a Page" 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/
