How to Add a “Tweet This Post” Button to WordPress in Less Than 60 Seconds

In terms of using Twitter as a business tool, I have learned one key thing over the last couple of months: that very few companies actually Tweet original content.  In an effort to drive traffic to their sites, most companies large and small will grab onto anything they believe is newsworthy—swine flu updates, MSN headlines and phrases from motivational posters being three of the more popular as of late.  On one hand this incessant regurgitation of content can be a problem (or at least an annoyance) for those of us searching for fresh takes and otherwise unreported news.  But on the flip side, there is also a BIG opportunity here for bloggers who generate original stuff.  And how can you take advantage of this opportunity?  By giving these content redistributors a one-click way to promote YOUR blog postings with a ”Tweet This Post” button.

So how does a “Tweet This Post” button work?  It’s actually a pretty simple concept.  If a visitor to your blog likes one of your posts, he or she can simply click the “Tweet This Post” button.  When the visitor does this, a very small (and invisible) piece of code does three things:

  1. Grabs the Title of your blog posting;
  2. Converts the existing URL of your post into a TinyURL; and
  3. Pastes both of them into the visitor’s “What are you doing?” box on their Twitter home page.

At this point, the visitor needs only to click their “Update” button, and bingo—a link to your blog posting is sent to each of their (potentially thousands of) followers.  The code to make this happen is surprisingly compact, and looks something like this:

$shortenedurl = file_get_contents(’’ . urlencode(get_permalink()));

” title=”Share on Twitter”>’Twitter’
Tweet This!

The first part of the code takes advantage of an API provided by the good people at, and saves you from having to mess around with the Permalinks settings within WordPress.  The second part of the code is the piece that talks to the visitor’s Twitter account, and displays whatever “Tweet This” icon you choose to use.

As an aside, please do not use a direct link to the tweetie.jpg file from this site.  Either copy the file into your own ‘images’ directory and link to it from there, or make your own icon.  Thanks! ]

This entire piece of code, including the Begin and End comments, needs to be pasted into your Single Post Template (typically single.php), which can be accessed from the Design – Theme Editor tab in WordPress.  In terms of exactly where to put it, this will be up to you.  As you can see from this page, I position mine at the bottom of my posts, so people can Tweet each post while it is fresh in their minds.

If you have any questions regarding the use of this code in your WordPress blog, please leave a comment here with two things in mind: 1) this code has only been tested in WordPress, and 2) I’m a blogger, not a .php programmer.  If you can live with this, I’d be glad to try and help.

Also, social bookmarking traffic is extremely important to us here at, so if you like this article please Sphinn it, Digg it or Tweet it.  Thank you for your support!

Related Posts

Leave a Reply

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