February 5th, 2011 by

You can show number of your Twitter followers by using this function. If you are a WordPress user, simply copy and paste it into the functions.php file.

<?php
function get_twitter_followers($username) {
$twitter_count = get_option("twitterfollowerscount");
if ($twitter_count['lastcheck'] < ( mktime() - 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name= . "$username"');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$twitter_count['count'] = $match[1];
}
$twitter_count['lastcheck'] = mktime();
update_option("twitterfollowerscount",$twitter_count);
}
return $twitter_count['count'];
}
?>

Call the function like:

<?php echo get_twitter_followers("yourtwitter"); ?>

That’s it. Now you can brag with your popular Twitter account ;)

One Response to “Show number of Twitter followers function”

  1. whatsapp says:

    Hey Thanx for this. I´m going to use it1

Leave a Reply