Twitter follower count using PHP in Wordpress

Twitter follower count using PHP in WordPress

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.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “Twitter follower count using PHP in WordPress”

  1. 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 Reply

Your email address will not be published.