Showing the amount of subscribers you have on your RSS feed is great, especially if you have a great amount of loyal subscribers. The same can be said if you display your Twitter followers and Facebook fan page.

What if you could display these counters as text, instead of image or without the use of any javascript?

Well have you noticed my sidebar lately? I have added the number of people who has subscribed to my blog via RSS feed or RSS email.

Would you like to have this on your blog as well?

[box type=”important”]MUST Install Exec-PHP Plugin[/box]

In order for the counters to work on your blog then you MUST execute the PHP codes below. You can do the by installing the Exec-PHP WordPress plugin. The Exec-PHP plugin executes PHP code in posts, pages and text widgets.

So before you install these codes on your blog to display the counters, you firstly need to install the Exec-PHP WordPress plugin.

[box type=”red”]How To Display Feedburner Subscribers As Text[/box]

feedburner counter
Copy the code below and paste it in your sidebar as a text widget where you want your Feedburner Subscribers counter to be displayed.

<?php
function WM_fb_count ($fb_user) {
$fburl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=". $fb_user;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL, $fburl);
	$stored = curl_exec($ch);
	curl_close($ch);
	$grid = new SimpleXMLElement($stored);
	$rsscount = $grid->feed->entry['circulation']+0;
	return number_format($rsscount);

}

function WM_fb_count_run($feed) {

	$fb_subs = WM_fb_count ($feed);
	$fb_option = "WM_fb_sub_value";
	$fb_subscount = get_option($fb_option);
	if (is_null($fb_subs)) { return $fb_subscount; }
	else {update_option($fb_option, $fb_subs); return $fb_subs;}

}

function WM_fb_sub_value($feed) {

	echo WM_fb_count_run($feed);

} ?>

Copy the code below and paste it under the code above (in the same widget).
Replace WebmasterSuccess with your Feedburner ID to have your Feedburner subscribers completed.

<?php WM_fb_sub_value('WebmasterSuccess'); ?>

[box type=”green”]How To Display Twitter Followers As Text[/box]

twitter counter
Copy the code below and paste it in your sidebar as a text widget where you want your Twitter Followers counter to be displayed.

<?php
function WM_twitter_followers ($twitter_user) {

	 $url="http://twitter.com/users/show.xml?screen_name=". $twitter_user;
	 $ch = curl_init();
	 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	 curl_setopt($ch, CURLOPT_URL, $url);
	 $data = curl_exec($ch);

	 curl_close($ch);
	 $xml = new SimpleXMLElement($data);
	 $tw_fol_count = $xml->followers_count;
	 if ($tw_fol_count == false) { echo '512'; }
	 else { echo number_format($tw_fol_count); }

}
?>

Copy the code below and paste it under the code above (in the same widget).
Replace BabyBoyKharim with your Twitter username.

 <?php WM_twitter_followers ('BabyBoyKharim'); ?>

[box type=”blue”]How To Display Facebook Fan Page Counter As Text[/box]

facebook counter
Copy the code below and paste it in your sidebar as a text widget where you want your Facebook Fan Page counter to be displayed.

<?php
// Get Facebook Fan Count //

function WM_fb_fan_count($fb_id){
         $count = get_transient('fan_count');
    if ($count !== false) return $count;
         $count = 0;
         $data = wp_remote_get('http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id='.$fb_id.'');
   if (is_wp_error($data)) {
         return 'Error getting number';
   }else{
         $count = strip_tags($data[body]);
   }
set_transient('fan_count', $count, 60*60*24); // 24 hour cache
echo $count;
}
?>


The image above shoes you how to get your Facebook fan page ID. This ID is required if you want to display the number of fans you have.

Replace the ID in the code below with your Facebook ID to display your counter.
Copy the code below and paste it under the code above (in the same widget).

 <?php WM_fb_fan_count ('154784051207520'); ?>

[box]In Conclusion…[/box]

Displaying your counters in text rather than image will help to reduce the load time of your bog.

Please leave me comment and tell me how this works for you, or if you need further help installing your counters.

21 comments

  1. igor

    Reply

    Great thank you
    The facebook dosent show nothing even with your Id
    Is there any Bug???

  2. Mahendra Yadav

    Reply

    I wanted to show all the text counters in my Sidebar. I was knowing about this Plugin, I will try to install it and add all text counters of sites.

  3. Ayesha

    Reply

    Gorgeous fine job, thanks for putting up! this code helps me a lot. This is such an massive post. I’m searching for the code to display on facebook for a long time and today my search has finished.

  4. Chris

    Reply

    Hey, good post, just wondering is it possible to install a counter that displays your total number of readers (ie. Twitter + Facebook + RSS + Google Plus) etc.? Thanks 🙂

  5. Reply

    Wow! This is really interesting and innovative article. These given tools are beneficial for website as traffic purpose. I really enjoyed your piece of coding related to social media tools on websites. Keep sharing such innovative information.

  6. Beth

    Reply

    I don’t have enough idea with such codings, so this simple tutorials can absolutely be a great help to me. It is great you’ve shared this one to us.

  7. Abelate

    Reply

    Yes, such things like this one may help to free your traffic channel so you can work faster. It’s less radical than get pictures download disabled in browser

  8. Marian

    Reply

    Hey, Kharim! I thought slow loading time is because of hosting providers, but I see now that some tools might be to blame. Thanks for sharing.

  9. Megan Brown

    Reply

    Thanks a lot for this as this is very much true that displaying counter in text reduce load time.

    Surely going to do this ASAP for my new one.

Leave a comment

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