Reveal Template

Description

Designers and developers know that it can sometimes be confusing and frustrating to determine the exact template being utilized to render the currently displayed page in WordPress. Sometimes page or category specific templates exist, or a page/post has been set by the post author to use a particular template, or the current theme doesn’t employ certain templates causing WordPress to fall back to others.

This plugin relieves that aggravation by assisting designers and developers by displaying the template being used to render the currently displayed page in WordPress. This can be shown in one or more of the following methods:

Admin bar

By default, the theme-relative path to the theme template file used to render the page is shown in the admin bar. The settings page for the plugin, at ‘Design’ -> ‘Reveal Template’, allows you to control and configure this particular method. Note: even if enabled by the setting, the admin bar entry also only appears if the admin bar is showing and if the user has the ability to see the revealed templated.

Site footer

By default, the theme-relative path to the theme template file used to render the page is shown in the site’s footer. The settings page for the plugin, at ‘Design’ -> ‘Reveal Template’, allows you to control and configure this particular method. Note: even if enabled by the setting, the footer output only appears if the theme follows the recommended practice of calling the wp_footer() template tag) at some point and the user and the user has the ability to see the revealed template.

Widget

A widget named “Reveal Template” is made available which can be used to display the theme template file used to render the page in any widget location.

Shortcode

A shortcode called ‘revealtemplate’ is made available which can be used in post/page content to display the theme template file used to render the page. Currently it supports two possible attributes:

  • ‘admin’ : Can either be 1 or 0 to indicate if the template name should be revealed to admins only. 1 means to admins only, 0 to all visitors. The default is 1.
  • ‘type’ : The template path types. Must be one of ‘absolute’, ‘filename’, ‘relative’, or ‘theme-relative’. Read the documentation for more information on what each of these mean.

Examples: [revealtemplate type="absolute"], [revealtemplate type="filename" admin="0"]

Template Tag

A template tag is also provided which can be used to display the theme template file used to render the page.

<?php c2c_reveal_template(); ?>

By default, c2c_reveal_template() will echo the template name. To simply retrieve the template filename rather than displaying it:

<?php $template = c2c_reveal_template( false ); ?>

The template tag also takes a second argument which be can be one of the following: absolute, relative, theme-relative, filename. This determines the path style you’d like reported. If not specified, it uses the default defined in the plugin’s settings page.

Examples of path types:

  • “absolute” : /usr/local/www/yoursite/wp-content/themes/yourtheme/single.php
  • “relative” : wp-content/themes/yourtheme/single.php
  • “theme-relative” : yourtheme/single.php
  • “filename” : single.php

This plugin is primarily intended to be activated on an as-needed basis.

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Template Tags

The plugin provides one template tag for use in your theme templates, functions.php, or plugins.

Functions

  • <?php function c2c_reveal_template( $echo = true, $template_path_type = '' ) ?>
    Formats for output the template path info for the currently rendered template.

Arguments

  • $echo (bool)
    Optional. Echo the template info? Default is true.

  • $template_path_type (string)
    Optional. The style of the template’s path for return. Accepts: ‘absolute’, ‘relative’, ‘theme-relative’, ‘filename’. Default is ”, which causes the function to use the template path type configured via the plugin’s settings page.

Examples

  • <?php //Output the current template
    c2c_reveal_template( true, 'theme-relative' );
    ?>

  • <?php // Retrieve the value for use in code, so don't display/echo it.
    $current_template = c2c_reveal_template( false, 'filename' );
    if ( $current_template == 'category-12.php' ) {
    // Do something here
    }
    ?>

Screenshots

  • The plugin's settings page.
  • The 'Reveal Template' widget.
  • The admin bar entry.

Installation

  1. Whether installing or updating, whether this plugin or any other, it is always advisable to back-up your data before starting
  2. Unzip reveal-template.zip inside the /wp-content/plugins/ directory for your site (or install via the built-in WordPress plugin installer)
  3. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  4. Optionally customize the plugin’s settings by clicking the plugin’s ‘Settings’ link next to its ‘Deactivate’ link (still on the Plugins page), or click on the ‘Design’ -> ‘Reveal Template’ link, to go to the plugin’s admin settings page. Or use the ‘Reveal Template’ widget. Or use the shortcode.

Reviews

Ogwekkuminogumu (Museenene) 22, 2016
Works as advertised, very clean interface, great documentation.
Ogwekkumi (Mukulukusa) 17, 2016
Does what its says on the box. Handy while developing or working on a site.
Ogwomwenda (Mutunda) 3, 2016
This is a right plug-in for plug-in developers. I was investigating a third party theme for some changes and this plug-in made my life easier by telling me exactly where to look for code.
Read all 16 reviews

Contributors & Developers

“Reveal Template” is open source software. The following people have contributed to this plugin.

Contributors

Translate “Reveal Template” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

3.5 (2020-07-18)

Highlights:

  • This feature release adds an admin bar entry to reveal the current template, updates the plugin framework, adds a TODO.md file, updates a few URLs to be HTTPS, expands unit testing, and updates compatibility to be WP 4.9-5.4+.

Details:

  • New: Add integration with admin bar
    • New: Add admin bar entry for revealing template
    • New: Add setting to control if admin bar entry should appear (defaulted to true)
    • New: Add can_show_in_admin_bar() for determining if the admin bar item should be shown
    • New: Add new screenshot
  • New: Add TODO.md and move existing TODO list from top of main plugin file into it (and add items to it)
  • Fix: Correct typo on plugin settings page
  • Change: Update plugin framework to 050
    • 050:
    • Allow a hash entry to literally have ‘0’ as a value without being entirely omitted when saved
    • Output donation markup using printf() rather than using string concatenation
    • Update copyright date (2020)
    • Note compatibility through WP 5.4+
    • Drop compatibility with version of WP older than 4.9
    • 049:
    • Correct last arg in call to add_settings_field() to be an array
    • Wrap help text for settings in label instead of p
    • Only use label for help text for checkboxes, otherwise use p
    • Ensure a textarea displays as a block to prevent orphaning of subsequent help text
    • Note compatibility through WP 5.1+
    • Update copyright date (2019)
  • Change: Note compatibility through WP 5.4+
  • Change: Drop compatibility with version of WP older than 4.9
  • Change: Update links to coffee2code.com to be HTTPS
  • Change: Update screenshot
  • Unit tests:
    • New: Add tests for register_filters(), options_page_description()
    • New: Add test for setting name
    • Change: Store plugin instance in test object to simplify referencing it
    • Change: Use HTTPS for link to WP SVN repository in bin script for configuring unit tests

3.4.2 (2019-12-27)

  • New: Unit tests: Add test to verify plugin hooks plugins_loaded action to initialize itself
  • Change: Note compatibility through WP 5.3+
  • Change: Update copyright date (2020)

3.4.1 (2019-06-16)

  • Change: Return an empty string instead of null when the template path string shouldn’t return anything
  • Unit tests:
    • Change: Update unit test install script and bootstrap to use latest WP unit test repo
    • Fix: Use explicit string value instead of referencing undefined variable
  • Change: Note compatibility through WP 5.2+

Full changelog is available in CHANGELOG.md.