Get Twitter follower count

Adding the first section of code to your functions.php & don't forget to change $name = 'problogdesign'; to your twitter user name. Then add the second section of code to your template where you wish to display your twitter follower count. Special thanks to Michael Martin of problogdesign.com.

function update_twitter_count() {
$name = 'problogdesign';
$url = 'http://api.twitter.com/1/users/show.xml?screen_name='. $name;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$xml = new SimpleXMLElement($data);
$count = $xml->followers_count;
$count = (float) $count;
$count = number_format($count);
update_option('twitter_followers', $count);

function twitter_count() {
	echo get_option('tb_twitter_followers');

if (!wp_next_scheduled('your_hourly_hook')) {
	wp_schedule_event(time(), 'hourly', 'your_hourly_hook');
add_action('your_hourly_hook', 'update_twitter_count');

Comments  Leave a Reply

  1. Kelvin Alfonso July 27, 2014 at 1:51 am

    Making this a shortcode would be awesome as well.

  2. Tweets that mention Wordpress Get Twitter follower count – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com November 4, 2010 at 7:32 pm

    […] This post was mentioned on Twitter by WPSNIPP, WPSNIPP. WPSNIPP said: #wordpress Get Twitter follower count http://bit.ly/aIM8v1 #tips #help #blog […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!