Display Twitter Follower Count as Text on Blogs

When it comes to showing off your blogs power subscriber count definitely plays a role. Gaining much popularity in this space is Twitter which can fetch any new or even well established blogs the right exposure in no time. A Twitter badge or a recent tweets sidebar widget can help you in feeding contents  shared on Twitter to your blog readers. Twitter follower count can be displayed using service like Twittercounter.com. But if you want to beautify or style it, displaying Twitter follower count as plain text can do the trick.

Twitter counter php code


In order to display Twitter counter in text format you have to use this php code snippet. Add this code to sidebar.php, header.php or footer.php if you are using WordPress. If you are using Thesis WordPress theme you may add this to ‘Thesis OpenHook’. It is the simplest way to add php codes to Thesis theme. Make sure that you check the ‘Execute PHP on this hook’ before saving. The thesis_hook_before_sidebars would be the best hook to display twitter counter.


$twit = file_get_contents(‘http://twitter.com/users/show/TWITTER_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 ‘<div id=”twitter-counter”><strong>’.$tcount.’ </strong> Followers</div>’;


In the above code change TWITTER_USERNAME to your Twitter username. The account details are included in .xml file provided by Twitter. To change the style and format in which the text is displayed you can tweak your CSS entries accordingly. We used the following CSS to style our text display.

.custom #twitter-counter {

If you are using Thesis WordPress theme add this code to custom.css file located under WordPress admin panel. Go to Thesis> Custom file Editor. From there select custom.css and add the code. Good to go.

Thesis Hooks Twitter counter code


1 Response

  1. anwar115 says:

    thanks for this new info . . .
    am going to do it in my blog . .

Leave a Reply

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