you can easily show twitter follower count in your wordpress site. In this tutorial we used twitter xml api for fetching Twitter follower count using PHP. You can place the twitter count in header section or footer section or sidebar section of wordpress.

Twitter follower count using PHP in WordPress

 

Twitter follower count using PHP in WordPress

Twitter follower count using PHP in WordPress

Using following code you can print the twitter followers count.


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
$twitter_api = file_get_contents('http://twitter.com/users/show/USERNAME.xml');
$text_output = '<followers_count>'; $end = '</followers_count>';
$page = $twitter_api;
$explode_content = explode($text_output,$page);
$page = $explode_content[1];
$explode_content = explode($end,$page);
$twitter_followers = $explode_content[0];
if($twitter_followers == '') { $twitter_followers = '0'; }
echo '<div><strong>'.$twitter_followers.' </strong> Followers</div>';

?>

You just need to replace the your name instead of USERNAME.

Written by Purab

My name is Purab, Here is my Personal Blog: wpapi.com. I contributor of many wordpress plugins and Drupal Modules. I am core developer of Drupal. Connect to on LinkedIn or Follow @purab on Twitter or Follow me on Google+ or Write Mail to purabdk@gmail.com or Chat with me on Skype : purabdk

This article has 1 comment

  1. khela Reply

    i use:

    $url = "http://api.twitter.com/1/users/show.json?screen_name=MYTWITTERNAME";
    if( function_exists("json_decode") ) {
    $cont = json_decode( file_get_contents( $url ) );
    $cont = $cont->followers_count;
    } else {
    $social_url[$sn] = str_replace(".json", ".xml", $social_url[$sn] );
    $cont = file_get_contents( $url );
    $cont = substr( $cont, strpos($cont, "") + 17, strlen( $cont ) );
    $cont = substr( $cont, 0, strpos($cont, "") );
    }

Leave a Comment

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