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.
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.
A few tools are recommended to make fixing your particular blog validation issues easier. Mainly:
- The official W3C Markup Validation Service: http://validator.w3.org/
- 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/
- 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!
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“:
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.
1c) Fixing the “&” and the “<br>”
The <br> (without the closing /) is not valid XHTML, and the & characters (instead of &) 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:
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:
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.
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: