Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Editing a site's HTML in Wordpress

Hi there,

I would like to be able to access a site's HTML in Wordpress in order for fine editing/customization. At the moment, to access the HTML of the page I am going to Chrome Developer tools where I can see all the html for the site in the bottom left-hand window. But when I try and access it from the Wordpress dashboard, all I can find are files such as 'single.php', which are written using php loops and I cannot seem to trace where the original html elements are.

For example, for changing the number of columns in a contact form 'message' box.

Any ideas? Is there a plugin that can help me with this?

Regards,

Robert Young.

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

You should get familiar with wordpress's temlpate hierarchy. A single web page in wordpress, is almost always comprised of at least 3 separate files; the header, the footer, and the content. Many times if there is a sidebar, that will be a separate file, the search bar is usually a separate file, and so on. All of these files come together to load one web page. So a little bit of Template knowledge will allow you to make a pretty good guess what file the html is coming from. Also, another possibility is the PHP code in the WP templates are generating the html, and in PHP form it may not look much like HTML since it may have a lot of variables, functions, and concatenation all specific to PHP in there. Again though, a little understand of PHP will help you there.

What page is the contact form on? Is it on a contact page, the footer, a modal, some other page? It may be placed in a custom template called something like "Contact.php" if the author chose too. It could be in page.php (not likely though), it could be in a file called "page.contact.php" or in a file that looks like "page.34.php" where 34 would be the id of the contact page. That number will vary by each WP installation, no way to know unless you go to edit the page, and look in the URL, and you will see the id number in there.

Those are the types of files you are looking for. The problem you are facing is that the PHP is generating the HTML code you are viewing in the Dev tools. What you are viewing in the browser, is not actually what the file looks like in many cases. If the form has an ID or Class to it, (which is always a good choice) you should be able to open a file you think the the contact form might be in, and than search for that class or id. Somewhere in one of those template files is your textarea tags, which you can than use to set the number of columns. Good luck.

Andrew McCormick
Andrew McCormick
17,730 Points

Have you gone through the "How to Make a Wordpress theme" tutorials on Treehouse? Kevin sums it up nicely. I just wanted to add on about your comment that you look at the site in developer tools. Remember that almost any site with a CMS is going to be dynamically generated. Meaning that you will never find a single document in the Website's files that look exactly like what you are seeing in developer tools. All that code in developer tools is generated from multiple documents and a pulled from a database as Kevin mentioned. Your form could be hardcoded into a page template or it could be added through a plugin.

What I do if I just can't find where something is to do exactly what Kevin said. I find something that would be on the page I'm looking for such as textarea or class. I then search all the documents in my wp-content folder for that class or piece of code (I search the entire wp-content folder so it searches plugins as well as the parent theme if I'm using a child). I use Netbeans so easy for me to just right click on a folder in my project and search all documents and get a nice list of files where that search appears.

In other words... what Kevin Korte said :)

Kevin Korte
Kevin Korte
28,149 Points

Solid add-on advice! I've never heard of Netbeans, so even I learned something :)

Andrew McCormick
Andrew McCormick
17,730 Points

it's what all notcool kids use!