LimeTouch

Twitter has become ever so popular and everyone is rushing to start tweeting, if they have a blog, they would want it to be displayed. However if you actually cared about having a valid XHTML site, you would have noticed that the code provided by Twitter has a couple of errors.

I will cut to the chase and give you the valid code.

The valid Twitter code

<div id="twitter_div">
<h2 class="twitter-title">Heading title</h2>
<ul id="twitter_update_list"><li></li></ul>
</div>

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/Username.json?callback=twitterCallback2&amp;count=Number of tweets to display"></script>

Replace the Header title and Number of tweets to display with your desired value.

Here is what has been changed from the original code:

  1. A <li> tag has been added within the unordered list
  2. The ampersand (&) has been replaced with its character code (&amp;) to fix the validation errors

Now you can display your tweets without breaking your site’s validation. Hope this helps you!

5 comments so far

  1. May 21, 2008 at 10:49 am

    Ooh nice.. thanks! I never use Twitter before though. Maybe I should try..

  2. Jun 1, 2008 at 2:25 pm

    Thank you very much for this post…this saved me some time tonight. One additional note for improving performance, you can place the two “script” lines at the very bottom of the section of your page. That way, your page will load first, and then it will ping twitter for your latest tweets. If twitter is down, at least your users will be able to see the rest of your site.

  3. Jun 1, 2008 at 5:20 pm

    Thank you for the mention.

    More specifically, place the 2 script tags just before the </body> tags.

  4. Jun 15, 2008 at 4:47 am

    I was working on getting my blog Valid XHTML. Now I am done. Thanks for the twitter & & tip. There are actually a whole lot more buttons out there that mess up your validation with these…

  5. Jun 15, 2008 at 9:44 am

    Congrats on a job well done. I noticed you are using XHTML Transitional. Why would you not want to use XHTML Strict?

Post a comment

Please be polite and on topic. You are welcome to use HTML tags. Spam bots, don't even bother trying.

:

:

:

: