Add Twitter Retweet Button to Wordpress

Twitter was once a breading ground for 3rd party applications and add-ons but this year it seems Twitter is going through some changes that may kick popular services like TweetMeme to the curb in favor of it’s own features. Twitter recently announced on it’s blog, a retweet button of it’s own. This retweet button can be added to websites and blogs the same way TweetMeme’s retweet button can the, only issue now.. It doesn’t seem to recognize urls of posts, only the actual page it’s displayed on. This creates an issue to many bloggers on Wordpress and other platforms as posts are displayed on the homepage and category pages.

DragonBlogger, a great site for blogging tips, recently wrote about the new Twitter retweet button and Justin(Dragonblogger) noticed that although the retweet button was displaying in every post on the homepage the url and title all relate to the homepage itself, not the individual post.

This is an easy fix and i’m sure there will be a few wordpress plugins and updates to existing wordpress plugins that will quickly resolve this issue but in the meantime, here’s how to do it:

  1. First, checkout the Twitter retweet button creation page.
  2. Under Tweet Text your going to paste the php snippet that call the posts title: <?php the_title(); ?>
  3. Under the URL tab you are going to paste the php snippet that calls the permalink of a post: <?php the_permalink() ?>
  4. The rest is up to you.

When your done you will have some code at the bottom that looks something like the below(although it may be a little different depending on your customization settings you selected)

————————————————————————-

<a href=”http://twitter.com/share” class=”twitter-share-button” data-url=”<?php the_permalink() ?>” data-text=”” data-count=”vertical” data-via=”thefunnydrunk”>Tweet</a><script type=”text/javascript” src=”http://platform.twitter.com/widgets.js”></script>

————————————————————————-

Add your new code inside the loop somewhere on index.php and the archive / category page. This code should also be added to single.php inside the loop somewhere so that it shows on single pages. To see the retweet button in action, check out TheFunnyDrunk. Post a comment if you have any questions, concerns or suggestions.