Adventskalender Day 4 – Helper for Theme Development: Template Name in WordPress Admin Bar

041

themefiles
Once you got the idea of the WordPress template hierarchy, it’s quite easy to use. As the case may be (Archive, Single Pages e.g.), and therefor the status of the global WP_Query instance (called »Main Query«), WordPress will look up for the most relevant template in your theme directory. Starting at the most specialized template for the current Query, it will search for more universal templates and finaly for the index.php. The first template file found by this process will be included.

These generic templates are a powerfull tool to build very complex content structures without claiming authors to choose the right template on their own.

The name of the template file tells you in which case the file will be applied. For instance category-catpics.php is a very significant name. But it’s not allways that clear if you come from the other way arround: so it might be not very easy to find the themplate which is in charge for the current »page« you are looking at.

I often had this problem, particularly with more complex themes and so i wrote myself a small plugin, in fact a developer tool, which prints the template name right into the admin bar. Now I don’t want to miss this tool any more on any of my developing systems, I am working on themes.

tpl-name-in-admin-bar

Addendum:
The Plugin requires PHP in Version 5.3.0 or higher. If you can’t achieve this use Debug Objects or What the file

Post Sharing

Author Avatar

David is programmer of WordPress Plugins and Themes at Inpsyde.

Also Interesting

slack-blog

New Plugin: Slack Connector - Connect WordPress, WooCommerce and Slack

by Michael Firnkes

Initially we merely wanted to optimize our own Slack-processes. With automated notifications from our MarkettPress shop, the blog and our forums. The resul ...

Read more
vip

Inpsyde is the first WordPress.com VIP partner in Germany

by Michael Firnkes

Automattic has given us the title of WordPress.com VIP Service Partner, the first in Germany, Austria and Switzerland. Worldwide, there are only eleven com ...

Read more
wooexperts

Inpsyde is a WooExperts Gold Partner of WooCommerce

by Michael Firnkes

A few weeks ago, Inpsyde GmbH with MarketPress became a certified WooExperts Gold Partner. This is confirmation from WooThemes of our agency’s know-h ...

Read more
backwpup

BackWPup Pro: Secure WordPress Backup with Google Drive

by Michael Firnkes

The Pro version of our BackWPup plugin supports the backup of WordPress databases and files to Google Drive. But how do you set something like that up? And ...

Read more

Comments

7 Comments

Comments are closed.

  1. #1

    Simple and helpful! Also my small hint 😉 , is a part of the plugin Debug Objects and get also the template, but not always in the Admin Bar.
    A screenshot is easier to understand, see this

  2. #2

    Oups. I’m getting a fatal error with this line:

    =:o/

  3. #5

    i wrote a small function 🙂

    domain.de?tmpl=x

    • #7

      Indeed, it’s slightly more pragmatic to pick up the name from the global variable, in case of plugins touching these directly. But writing the string directly to the head element of your document is a bit to pragmatic for me 😉

  4. #6

    sry
    instead of tmpl use debug in your url 🙂

    greetings