4

Is there a browser plugin or method to find which php template an item is coming from?

2

4 Answers 4

5

The Debug Bar together with the Debug-Bar-Extender will show you what template file is being used.

Debug Bar Extender showing the query template

4
  • When I'm using a WP theme, there's various times when I see an embedded word or element and I want to know which php template it comes from. Commented Apr 6, 2011 at 21:56
  • @dreamgrowers: Ah, you are talking about just a snippet of HTML in the output? That is (almost?) impossible to figure out automatically, because they can come from anywhere: a template, your database, a generated string, some external data... I usually search my wp-include and wp-content directory for a piece of a surrounding text (a class attribute for example), to pinpoint the most likely sources.
    – Jan Fabry
    Commented Apr 7, 2011 at 5:53
  • That's almost it. Although each area of the page is driven my a different template. How can I find out for a particular item or all items? Commented Apr 8, 2011 at 6:25
  • @dreamgrowers: This si very hard to do in a generic way. As AutoBLogged suggested, your best chance is to place a comment at the top and at the bottom of each template file, so you can look at the source code of the HTML page to find out where it comes from.
    – Jan Fabry
    Commented Apr 8, 2011 at 8:54
3

You could just add an HTML comment into each template file and then view source to see where the content you are trying to track down it is coming from.

1
  • Thats what I do to all my templates just to make it easier to track down weird template hierarchy issues.
    – Chris_O
    Commented Apr 6, 2011 at 7:42
1

the method I've been using is to find the item - such as a page title or whatever by using firebug extension for firefox. This will usually result in finding the related css class or id name for that item/element.

Then in dreamweaver I use the search function to find that class name from all of the files in the wordpress wp-content folder. Not sure of other programs like dreamweaver that have this search function but surely they exist.

I just wish there was a browser add on that would do for the php files what firebug does for css & html

0

The Query Monitor plugin is a very powerful tool for doing this. It shows the template and the queries and hooks the page generates; plus their load order, priority and whether it's core, parent theme, child theme or plugin. Very handle to have in your toolbox!

In WP Cli:

wp plugin install query-monitor --activate

On the repo: http://wordpress.org/plugins/query-monitor/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.