treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Wordpress: html validation errors

  • I'm creating a wordpress theme.
    Every time I add <!--more--> in the back-end posts section of wordpress it creates something that says "Continue reading ".

    However there is always a <p></a></p> right below it. I can't find what the problem is.

    Html
    <p>Continue reading &raquo;</p>
    <p></a></p>
    <p> Posted in <a href=\"http://localhost/wp-jamy/?cat=1\" title=\"View all posts in Uncategorized\" rel=\"category\">Uncategorized</a> | <a class=\"post-edit-link\" href=\"http://localhost/wp-jamy/wp-admin/post.php?action=edit&amp;post=16\" title=\"Edit post\">Edit</a> | <a href=\"http://localhost/wp-jamy/?p=16#respond\" title=\"Comment on Lorem Ipsum Dolor Sit Amet\">Comment;</a></p>


    Php
    <?php the_content('<p>Continue reading &raquo;</p>'); ?>
    <p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('Comment;', '1 Comment &#187;', '% Comments &#187;'); ?></p>


    Any help would be appreciated.
  • I found a solution (for anyone interested).
    As soon as I took the <p></p> away it stopped having the problem. However I wanted "continue reading" on a separate line. So after adding spans and <div class="clear"></div>, etc. (It would still have an extra <p> at the beginning of the text, but it wouldn't close it, eve if I did in the php)

    I changed it to:
    <?php the_content('<br /><br />Continue reading &raquo;'); ?>

    which validates nicely.

    Weird problem don't you think?
  • very weird...
  • its normal. <p></a><p> is an error to HTML validation because of the </a>. you're basically asking any HTML processor to process an ending part of a hyperlink to an unknown location inside a paragraph of nothing.
    There are two easy ways to fix this. either remove </a> or change it to '<a href="url">label</a>' but replace url with an actual url to a webpage and label will be the text that will appear as a hyperlink.
  • By default WP output is:

    <p> <a href="http://localhost/wordpress/hello-world/#more-1&quot; class="more-link">
    <p>Continue reading &raquo;</p>
    <p></a></p>


    We can see the first < p > tag don't have the end tag.

    If your theme have the loop.php file take a look on this code:

    <?php the_content('<p>'.__('Continue reading &raquo;').'</p>');


    and changes it to:

    <?php the_content(__('Continue reading &raquo;')); 


    and it will output this:

    <p> <a href="http://localhost/wordpress/hello-world/#more-1" class="more-link">Continue reading &raquo;</a></p>