HOW TO: Build a XHTML Valid Wordpress Blog with DISQUS Plugin [Download]

Update (08 June, 2010): A copy of DISQUS Wordpress plugin version 2.33.8752 with the XHTML errors fixed is available for download at the bottom of this post. Enjoy :)


The last couple of days, I was reading about how to get your site to rank higher in Google. There are many tweaks you can do to insure that your site is Google friendly. One of the controversial topics was whether having your pages XHTML/HTML valid helps in SEO ranking or not. It’s clear that if your site has made a mess out of the HTML code, a search engine spider might have a tough time reading and parsing your page, which might lead to errors and in turn lower ranking. So, I decided that it’s better to be safe than sorry, and started converting the entire blog to XHTML 1.0 Transitional valid.

Thoughtpick Valid XHTML

Thoughtpick Valid XHTML

Let’s start…

The main issues targeted by this post

On the Thoughtpick blog, we have a few plugins that were causing XHTML validation issues. Mainly:

  • DISQUS Commenting System: At least 4 or 5 XHTML validation errors were generated by this plugin. The solutions are listed below.
  • Wordpress 2.8+ “role” problem, and how to fix it.
  • Youtube and Vimeo embed object issues: the <embed> tag is invalid for XHTML 1.0, to fix the issue, I wrote a small function.

Tools recommended

A few tools are recommended to make fixing your particular blog validation issues easier. Mainly:

  1. The official W3C Markup Validation Service: http://validator.w3.org/
  2. Total Validator – this tool provides an easier to read way of locating HTML syntax errors and made this task much easier: http://www.totalvalidator.com/
  3. Wordpress admin section for editing the theme. You need to “chmod 666” your them files to be able to edit from within WP-Admin. Or a text editor and your favorite FTP client. Your call!

The fixes…

1. Fixing the broken XHTML of DISQUS

DISQUS Commenting System (version: 2.12.7121) seems to result in a bunch of errors. Keep in mind that the line numbers are just given to help you locate the line easier, but if you have the slightest difference in version, you need to look for it. Here they are and how to fix them:

1a) DISQUS has an extra “</a>”

DISQUS has an extra “</a>” on line 322 of the “disqus-comment-system/disqus.php” file. Just change the “… . $post->ID . ‘”>Comments</a>” to “… . $post->ID . ‘”>Comments“:

DISQUS missing tag and problematic id

DISQUS missing tag and problematic id

1b) DISQUS uses invalid “id” tags

The same “disqus-comment-system/disqus.php” file, line 322 as well, change the “… ‘#disqus_thread” id=”‘ …” to “… ‘#disqus_thread” id=”dsq …”. Just add ‘dsq‘ at the beginning of the ids to avoid the “value of attribute “id” invalid: “1″ cannot start a name” XHTML validation errors.

That’s not all, you also need to change the Javascript at line 297 to use accommodate for the ids starting with “dsq” instead of being just numerical. See the image for the changes:

DISQUS Replace 'dsq' in IDs

DISQUS Replace 'dsq' in IDs

1c) Fixing the “&” and the “<br>”

The <br> (without the closing /) is not valid XHTML, and the & characters (instead of &amp;) is also invalid. In the “disqus-comment-system/comments.php” file, on line 21, replace the “… echo $comment['message']); …” by the following str_ireplace() function:

DISQUS fixing the br and amps

DISQUS fixing the br and amps

1d) DISQUS outputs empty unordered lists (ul)

The last DISQUS issue is that if there are no comments, it displays an empty unordered list <ul id=”dsq-comments”></ul>. To fix that, we simply need to check if there are comments or not before we output that. You need to do the following changes to the <ul id=”dsq-comments”> and </ul> parts of the code on lines 7 and 25:

DISQUS fix empty unorder list error

DISQUS fix empty unordered list error

To get the the fixed code for DISQUS Wordpress plugin version 2.12.7121, they are uploaded on pastebin: download comments.php file, download disqus.php file.

2. For Wordpress 2.8+, remove role=”search”

Wordpress 2.8+ uses the HTML5 tag “role”. To validate successfully as XHTML 1.0, you need to remove that. Just remove “role=”search”” from the wp-includes/general-template.php file. You can download the edited version of general-template.php here for Wordpress v2.8.4.

Remove role=search from general-template.php

Remove role=search from general-template.php

3. Fix your header.php, index.php and footer.php to be XHTML valid

This part is custom for each blog. Mainly you need to make sure that each <tag> is closed with relevant </tag>, or using the alternative <tag /> annotation. Another point to keep in mind is that XHTML “id” attributes must start with an alphabetical letter (not a number), and all tags must be lower case (<META … /> or <BR /> will result in errors). Finally, all images must have the “alt” attribute defined.

4. Youtube embeds are invalid XHTML

Youtube embed code has an invalid XHTML tag “embed”. I wrote a function that does DOM traversal to fix this issue, without bothering your blog contributors to use a custom made function. I will discuss the code in another post, so subscribe to our feed and keep an eye out for the post. Meanwhile, the Fix Video Objects function code can be found here.

If you face any problems or have any questions, feel free to ask…


Update (08 June, 2010): This post is quite popular on Thoughtpick blog; so I decided to upload the fixed version of DISQUS plugin version 2.33.8752 with the XHTML errors fixed to make life easier for our readers:

Download XHTML-fixed DISQUS Wordpress Plugin via local link, or RapidShare link [28KB file].

Comments and Reactions

  • W3c Validation
    Thanks for the good information...very good blog site.
  • Disqus has changed a lot of things in version 2.41... all of those errors are fixed but there are new ones.
  • Your blog is so informative … ..I just bookmarked you....keep up the good work!!!!
  • Good post, just what I was looking for!
  • Nice post, we are currently switching over to disqus will save and share the post.
  • Thanks for guidance on building valid xhtml wordpress blog with disqus.
  • ive had errors with it too
  • I just uploaded the XHTML valid DISQUS Wordpress plugin files (v2.33.8752). You can download it at the bottom of the post.

    Just extract at the /wp-content/plugins/ folder, replacing the current DISQUS files or using it as a fresh install, and you're ready to go. No more DISQUS XHTML validation errors. :)

    Enjoy!
  • I didn't tackle this issue on full scale yet, so you're going to need to do some researching to learn what's valid and what's not. Keep in mind, not all browsers support all the features of CSS3.
  • can you take the plugin and apply it directly to each page or just stand alone pages.
  • Wow amazing information. It will help me a lot in installing the DISQUS plugin in my blog. thanks a lot for the information .Keep up the good work.
  • this was a really good article.thanks for sharing the information.disqus system is really perfect.
    it allows the blogger to have greater control with comments.
  • good article!

    Happy to share your blog!
    Disqus is popular and useful.Disqus is good for my work and life.I like it very much.but every coin has two back.we should use the disqus to improve our working efficient
  • Wow that was great post, i'm gonna try in my blog soon. Thanks
  • Disqus is a great tool, I have it on many of my blogs already. It will only get better in the next few years..Disqus is a popular commenting platform...
  • Disqus is the top commenting platform in my opinion. Not only is Facebook Connect integration nice but allowing users to also use their Twitter accounts to leave comments is awesome.
  • Спасибо за статью, очень понравилась.
  • Hi Amer, thanks for this great post.

    Your updated versions of comments.php and disqus.php solved the XHTML validation errors I was getting. If you're reading this Disqus please can you fix them in the default code so we don't need to hack the code :)

    Amer - are you able to work your magic on the CSS that Disqus pumps out?

    I get W3C CSS validation errors no matter which built-in Disqus stylesheet I choose:
    - Narcissus (113 errors)
    - A (71 errors)
    - B (88 errors)

    There is an option to add your own Custom CSS code, but this doesn't seem to remove the built-in CSS rules Disqus applies. Any suggestions?

    I think you are using the Disqus Narcissus theme as you have 113 CSS errors from the Disqus plugin:
    http://jigsaw.w3.org/css-validator/validator?uri=http://blog.thoughtpick.com/2009/10/how-to-build-a-xhtml-valid-wordpress-blog-with-disqus-plugin.html
  • Hi, Thanks for commenting.

    I am aware of that, but CSS is too much of a hassle with the need to test on all those browsers from IE6 to the versions of Chrome until most bugs were ironed out (v4).

    If you are in the mood to take on this challenge, the DISQUS function file+function that embeds the "disqus.css?v=2.0" file is "disqus.php" (in my version line 222):

    function dsq_get_style() {
    echo <link rel=\"stylesheet\" href=\"" . DISQUS_API_URL ."/stylesheets/" . strtolower(get_option('disqus_forum_url')) . "/disqus.css?v=2.0\" type=\"text/css\" media=\"screen\" />;
    }

    Here, you can download the CSS file locally, and override this function (edit it directly) to link to the local file which you fix the CSS errors in.

    For me to put my head into CSS is too much of a hassle that I'd prefer to go back to WP's default comments. :)

    Hope this is helpful.
  • cheers Amer

    I think that disquss.css?v2.0 file contains just your own customizations, rather than the full Narcissus css file

    eg. mine has only 2 rules and reads:

    #dsq-content iframe, #dsq-popup-alert iframe {
    height: 355px;
    }

    /*
    * Narcissus theme customization
    */
    #dsq-content .dsq-header-avatar img {
    width: 32px;
    height: 32px;
    }


    Do you know the URL where I can download the original Narcissus css file in full (so I can look at how to over-ride parts of it?)

    Any idea how to over-ride for example "-webkit-border-bottom-right-radius" so that this property isn't called?

    ------

    82 #dsq-content #dsq-comments .dsq-header-avatar .dsq-drop-profile Property -webkit-border-bottom-right-radius doesn't exist : 5px 5px
    83
    #dsq-content #dsq-comments .dsq-header-avatar .dsq-drop-profile Property -webkit-border-bottom-left-radius doesn't exist : 5px 5px

    88 #dsq-content #dsq-comments .dsq-header-avatar .dsq-drop-profile Property _position doesn't exist : absolute absolute

    108 .dsq-overlay Property -moz-opacity doesn't exist : 0.8 0.8
blog comments powered by Disqus

Latest pingbacks

Share a post

Got an amazing campaign, web app or a social media related topic that you'd like to share with our readers?

Thoughtpick by email

For more Learn Social Media by Example reviews, don't forget to subscribe to our posts by email:

Like us on Facebook

Explore Thoughtpick

Our Archived Posts

We're on Twitter

We love Tweepi

Tweepi Logo

Follow the best and unfollow the bots, with the only Twitter management tool with stats!

Try Our #FF Helper App

FollowFriday Helper makes playing Twitter's #ff a piece of cake!

A brand new way to recommend tweeps based on how you tweet...

©2010 thoughtpick, copyrights reserved.