Show which template a page uses
Administrators see the theme file (or block template) that built the current page in the admin bar. Saves guessing when you edit a theme.
<?php
add_filter(
'template_include',
static function ( $template ) {
$GLOBALS['snipfire_template'] = $template;
return $template;
},
9999
);
add_action(
'admin_bar_menu',
static function ( $bar ) {
if ( is_admin() || ! current_user_can( 'manage_options' ) || empty( $GLOBALS['snipfire_template'] ) ) {
return;
}
global $_wp_current_template_id;
$file = str_replace( wp_normalize_path( WP_CONTENT_DIR ), '', wp_normalize_path( $GLOBALS['snipfire_template'] ) );
$label = ! empty( $_wp_current_template_id ) ? $_wp_current_template_id : ltrim( $file, '/' );
$bar->add_node(
array(
'id' => 'snipfire-template',
'parent' => 'top-secondary',
'title' => esc_html( 'Template: ' . basename( $label ) ),
'meta' => array( 'title' => esc_attr( $label ) ),
)
);
},
100
);
In these packs
- Developer tools: Maintenance mode, template names, page stats, environment labels and a WP-Cron viewer.