WordPress tip: Create a Tweetmeme “Retweeet” shortcode

October 14, 2009 at 9:15 am

Tweetmeme is a popular service that allow you to display “Retweet” button on your blog posts. Even if the code is easy to integrate on your single.php file, it can be very cool to create a shortcode that you can insert anywhere in your posts.

Paste the following code in your functions.php file in order to create the shortcode:

function tweetmeme(){
	return '<div class="tweetmeme"><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';
}
add_shortcode('tweet', 'tweetmeme');

Once done, you can display the Tweetmeme “retweet” button anywhere on your posts. In WordPress editor, make sure you are in HTML mode and insert the following:

[tweet]

When your post will be published, the shortcode will be replaced by the TweetMeme button.