Best way to find out which php file has generated

2019-01-21 23:37发布

Using Chrome you can right click - Inspect element to see the html code behind that element:

Chrome inspect element example

I wonder how to find which php file has generated that html. Maybe there is some tool to put a breakpoint into the html so the php server will stop when trying to generate it again?

I'm using WordPress locally. I'm on Ubuntu 14.04LMS. I'm using Sublime Text 3 with XDebug.


UPDATE 1

A WordPress plugin able to put, in every file, something like the following would be a good solution (I think from my beginner's viewpoint):

echo '<!-- name_of_the_php_file.php -->';

8条回答
狗以群分
2楼-- · 2019-01-22 00:14

Not all data is stored in html or php files in Wordpress.

It may be possible that the string you are looking for is coming from database since wordpress uses database to store variable data.

Please search database also

查看更多
贼婆χ
3楼-- · 2019-01-22 00:23

Unfortunately with wordpress you need to do some digging:

  1. Is it a page/ post / custom post (i.e. you can find the page in the admin section and edit it)
  2. If yes - look the the template assigned (posts don't usually have a template select field unless custom code added) and find the matching page template in your theme (page-whatever.php)(it might not be called what you see in the dropdown field, but in its notes it will have the name you see), or if a post you are looking for single.php or if custom post look for single-whatever.php.
  3. The above is default and will cover 60% of situations. But if you add a plugin and it adds new pages, the page template will be in the plugin and the real fun starts.
  4. If a plugin is developed with user mods in mind, it should have its pages in 1 location or in a functional set folder. Have a look for the above files in these locations if they exist or in the general plugin folders.
  5. If still no luck, have a look for add_action('save_post', 'whatever'); there may be code stating return $template , this will prob also have the post type in the function. Look for the path its calling
  6. Another way to add a page is through a url rewrite (search through the files for rewrite). It will contain a path somewhere to the file (there are a couple of methods of doing this so look them up so you will recognise them).

If you think you have found the correct template, try a echo to see if it appears on screen. If yes you have found the template, look at what you have follow the includes/ requires to appropiate .php files, you'll find your html somewhere either as html or php code creating html.

hopefully you find what you are looking for, but there are no rules really and other methods can exist including htaccess rewrites to point to php file, etc or a functions file creating pages on the fly

This might be a good point to mention if you ever create a entire plugin, store files logically and include from a file controller or plugin file. Store pages in a pages folder so they are easy to find.

Good luck!

update: filter to output path on template files

add_filter( 'template_include', 'show_path', 99 );

function show_path( $template ) {

            if($template):
                echo $template;
            else:
                echo "template path not found";
            endif;

    return $template;
}
查看更多
登录 后发表回答