Time for action – finding and fixing errors

The next step is to find the error, so that we can fix it.

  1. Open the page you've just validated in your browser.
  2. Using your browser's developer tools, display the page source. I'm working in Chrome, so I'll navigate to View | Developer | View Source.
  3. Look for the line numbers where the errors are—lines 61 and 78, as shown in the previous screenshot. Here they are as displayed in Chrome. I've highlighted line number 61 and you can also see line number 78:
    Time for action – finding and fixing errors
  4. The code on line number 61 is as follows (I've taken out the links to save space):
    <p class="entry-meta">by Rachel McCollin in <a href="" title="View all posts in Resources" rel="category tag">Resources</a>, <a href=" " title="View all posts in Software" rel="category tag">Software</a></p>
  5. Looking at the code, identify which template file it's being generated by. In this case, the relevant lines are inside <div class="content">, so I know they're in the main template file and not in one of the include files, such as sidebar.php or footer.php. Both lines 61 and 78 are displaying metadata and are enclosed in a <p class="entry-meta"> tag.
  6. Now, open the relevant template file and find the PHP which generates that markup. In the case of this page, the template file is index.php. The PHP generating those two lines is inside the loop, which is shown below:
    <p class="entry-meta">by <?php the_author_meta('first_name'), ?> <?php the_author_meta('last_name'), ?> in <?php the_category(", ") ?></p>

What just happened?

We opened the page we checked with the validator, identified the code causing the problem, and then found the PHP generating that code n the template file.

Sniffing out PHP from the HTML it generates in this way may seem a bit daunting at first, but the trick is to find HTML elements which form major areas of the site, such as <div class="content">. Then you can identify the HTML tags immediately surrounding the offending markup and trace that back to the PHP in the template file. If in doubt, always make a backup before you make any changes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.68.14