One Line "Tweet This" button for Twitter

[singlepic id=7 w=320 h=240 float=]

Since viewers of a page already had the ability to post that page to Facebook, I wanted to give them the ability to Tweet about it as well.

Solution: Twitter provides for you to call directly. By using the share function, we can allow users to post to their twitter feed without anything more than a single line of code. Twitter will handle authentication in the popup themselves. I put this in a popup window using so that my website will stay open in the background.

<a onclick="';url={{ page.slug }}','C2G','menubar=no,width=550,height=450,toolbar=no'); return false;" href="#">Tweet this page</a>

The {{ page.slug }} variable is a django variable that puts a link directly to the current page. It can be removed to point to a static page, or generated with PHP if your site is written in PHP. One of the cool things about the share function is that it automatically uses a URL shortener for you, so all you have to do is provide the full URL.

As always, you can replace the “Tweet this page” text with a cool Twitter image.

This entry was posted in Twitter and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *