Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

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.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Developer tools
  • Tested with WordPress 7.1
PHP
<?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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.