I am trying to make some changes to PHP files in WordPress, but it is taking me a long time to find which PHP file to edit. Is there a way to know which PHP file generated a given page?
Thanks!
More information:
I understand the basic outline of WordPress templates like header.php and single.php. However, I am having a hard time walking through the many theme-specific template files and finding which one serves what purpose. Specifically, I am looking at a generated webpage and attempting to edit it. And I am resorting to inserting
tags inside each of the probable template files until I find the right one. Is there a way, perhaps through dev-tool, to see which php file generated the DOM?
It is possible to get a list of all the included files through the get_included_files() function in PHP.
Here is a PHP script to set in the footer.php file of your template :
This script will show you all the included files related to your template. In other words, you will have the possibility to know which file template is used.
Please, be sure to use this code only on your development mode and to delete it when you will be in production.
It is sometimes difficult trying to work out which template file within a theme is being used. First thing worth considering is the WordPress template hierarchy. This page from the Codex and in particular the diagram should be helpful to you;
http://codex.wordpress.org/Template_Hierarchy
Secondly, it can help if you add the body_class method to your theme’s
header.php
. It is designed to allow greater control of CSS through additional specificity, but by viewing the source through your browser dev tools you can quickly look at the classes added to the body tag and work out which template is being used;http://codex.wordpress.org/Function_Reference/body_class
How about putting a unique HTML comment in each template file?