X

How to Display Twitter Followers Count

Snippets by IsItWP

Are you looking for a way to show total number of Twitter followers on your WordPress site? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display Twitter followers count in WordPress.

Instructions:

All you have to do is add this code to your theme’s template file:

<?php
$twit = file_get_contents('http://twitter.com/users/show/USERNAME.xml');
$begin = '<followers_count>'; $end = '</followers_count>';
$page = $twit;
$parts = explode($begin,$page);
$page = $parts[1];
$parts = explode($end,$page);
$tcount = $parts[0];
if($tcount == '') { $tcount = '0'; }
    echo '<b> '.$tcount.' </b> followers.';
?>

Change ‘USERNAME’ in the above code to the Twitter username you want to get the stats from.

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 7 best WordPress poll plugins to grow onsite engagement and how to set up download tracking in WordPress with Google Analytics.

Comments   Leave a Reply

  1. This doesn’t seem to work any more. It always shows 0 followers for me and trying to access the xml url shows not found on Twitter.

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!