Reputation: 3987
Using Chrome you can right click - Inspect element to see the html code behind that element:
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 -->';
Upvotes: 26
Views: 69288
Reputation: 5937
Unfortunately with wordpress you need to do some digging:
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 callingIf 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.
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;
}
Upvotes: 5
Reputation: 615
Use this plugin "what the file" to find out the php file. Then rest it is to find out a function or something else by CTRL + F in any editor.
I want to add one more plugin which is not exactly for this purpose but it is very popular among WordPress developers and it solves this problem very well. The plugin is Query Monitor.
Upvotes: 23
Reputation: 9918
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
Upvotes: 1
Reputation: 59
Hope to find this plugin useful. use to search in files amd wasting enough time. Also i use What the file plugin as suggested before, it is a great way. But i think combining the String Locator this will have extra fun! String Locator
Upvotes: 2
Reputation: 238
Start page code
<?php
ob_start();
?>
HTML content
...
...
<sapan>Original text</span>
....
...
end page code.
<?php
/* get and delete current buffer && start a new buffer */
if ((($html = ob_get_clean()) !== false) && (ob_start() === true))
{
echo preg_replace('~<sapan>Original text</span>~i', '<!-- name_of_the_php_file.php -->', $html, 1);
}
?>
Note: Sory, my English not good.
Upvotes: 1
Reputation: 1574
First tack a backup of whole websiter, suppose /my-website
1.Right click on element for that you want to find php code
2.Cope CLASS or ID selector of that line
3.Search that CLASS or ID selector in editor inside /my-website folder, for this notepad++ and Dreamweaver editor is best.
Upvotes: 1
Reputation: 3987
Another possibility would be to copy an id or class from the html. Then search that string through the source code of the WordPress web application to put a breakpoint at every place where the string appears.
However, the string could be in the database. In that case, this method won't work.
Upvotes: 1
Reputation: 8659
Put an echo in your PHP pages to print their name in an HTML comment based on whether a session variable is set. Then set that session variable and enjoy.
if(isset($_SESSION['printPageName']) && $_SESSION['printPageName']=='true')
{
echo '<!-- ' . $_SERVER['PHP_SELF'] . ' -->';
}
The reason I say to use a session variable is so you can create some mechanism to where you can occasionally look at this for debug purposes, but users don't normally encounter it.
Upvotes: 5