Show Twitter Followers Count in WordPress

This WordPress snippet grabs and displays the number of Twitter followers the specified user has.

Instructions
Add this to your template file where you want it to be displayed.
*Change USERNAME to the Twitter Username you want to get the stats from.

<?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.';
?>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do NOT follow this link or you will be banned from the site!
%d bloggers like this: