How to Get Twitter Follower Count in WordPress?

I am neither the first nor the last one that will be writing about placing twitter follower counter in webpage. Though there already exist many widgets anyone can easily use and customize; see here and here; But those widgets have limited options in terms of color, layout and moreover they have their info attched (somewhere) in widget which does not feels good. Here’s my attempt on how to get follower count in twitter using PHP.

Step 1:
We will create a PHP file; lets say follower_count.php or whatever you’d like to name it. Then simply put following contents in that page.

<?php
$twitter_username	=	'designgala';	// please replace it with your twitter username
$tw	=	get_option("total_twitter_followers");
if ($tw['lastcheck'] < ( mktime()3600 ) ) { 	$xml	=	file_get_contents('http://twitter.com/users/show.xml?screen_name='. $twitter_username); 	if (preg_match('/followers_count>(.*)

Explanation:
I used 2 PHP functions file_get_contents() and preg_match() here. file_get_contents fetches twitter xml file and stores in buffere while preg_match searches followers_count for a match in the buffer returned by earlier function.

Step 2:
Now you can include above file using PHP include like below in any template file.

<?php include("follower_count.php"); ?>

Thats it. It will show twitter follower count.

[Photo Credit: JavaJunky via Flickr]

15 replys to How to Get Twitter Follower Count in WordPress?

  1. Pingback: Design Gala
  2. Pingback: Design Gala
  3. Pingback: WordPress Rocker
  4. Pingback: Anish Lama
  5. Pingback: topsy_top20k
  6. Pingback: Saroj Pandey
  7. Pingback: Gayath chaminda
  8. Pingback: Barbara Wilson
  9. Pingback: Jennifer R

Leave a Reply

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