How to Display Facebook Fans Count as Text in WordPress site

How to Display Facebook Fans Count as Text in WordPress site

You can add your Facebook fans count in different ways. The easiest way to display fans count is by using the official Facebook  Like Box social plugin. But what if you don't want to slow your site down by loading Facebook’s code? Or what if you are making something very custom and need to display Facebook page fans count as text instead of a box. Well, then you will like this tutorial. In this article, I will show you how to display your Facebook fans count as text on your WordPress site.

The first thing you need to do is to open your functions.php file, located in your WordPress theme, and then copy the following code and paste in it.

Free Download
function lj_fb_count($fb_ID=''){ 
if($fb_ID && get_site_transient('lj_fb_count')===false) { 
$fb_count = json_decode(wp_remote_fopen($url),false); 

//Caching count for Ten hours----------------------------
set_site_transient('lj_fb_count',$fb_count, 60 * 60* 10 );
echo $fb_count;

Now add this line of code in your theme template where you want to display your Facebook fans count. This could be in the sidebar.php, header.php, or basically anywhere you like. You can use your Facebook Page ID  as the function's input value.

<?php lj_fb_count('114877608587606');?>

That's it. You are done. I hope that this article helped you show Facebook fans count as text in your WordPress site/blog.  To get more such useful tips to consider following @lineshjose on Twitter. You can download this script from my GitHub repository.