DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Twitter and other third parties sites have great widgets that allow you to display how many times your posts have been retweeted. But how to do it in full text, without using a widget? Just read this recipe and you’ll know how you can easily do it.

The first thing to do is to open your functions.php file and insert the following function:

function tweetCount($url) {
    $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
    $element = new SimpleXmlElement($content);
    $retweets = $element->story->url_count;
        return $retweets;
    } else {
        return 0;

Once done, open your single.php file and paste the following:

$rt = tweetCount(get_permalink());
echo "Retweeted ".$rt." times.";



One Comment

  1. Any alternative for tweetmeme? They shutdown a few months ago.

Leave a Comment

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