How to: Display Facebook Page Fans count on your blog/website

How to: Display Facebook Page Fans count on your blog/website

Do you have a Facebook page for your business? Did you ever try to display your Facebook fans count on your blog/website? Some developers, using heavy plugins to display their Facebook fans count on their website. I don’t like to install those heavy plugins to do little things like this. So decide to create a simple script for display the fans count. Yeah, it’s done. This code is very simple. I think it’ll be very helpful for you.

step 1: Adding code to your site

We use the following PHP function to retrieve your Facebook fans count. Copy and paste it your common functions coded file like config.php, main_functions.php, engin.php, etc..

For example, WordPress uses the function.php file to write common custom functions for particular themes. If you are a WordPress developer open functions.php, paste this script, and save the file.

function fb_count($value='') {
$url=' fan_count FROM page WHERE';
if(is_numeric($value)) {
$qry=' page_id="'.$value.'"';
} //If value is a page ID 
else {
$qry=' username="'.$value.'"';
} //If value is not a ID. 
$xml = @simplexml_load_file($url.$qry) or die ("invalid operation"); 
$fb_count = $xml->page->fan_count;
return $fb_count;

step 2: Display Followers count

Now simply call that function anywhere you want to show your fans count on your site/blog. You can use your Facebook Page ID or UserName as a function’s input value. checkout the examples below and also try the live demo.

Function calling examples

  1. Input as a Page ID

    Facebook Likes:<?php echo fb_count('114877608587606');?>
  2. Input as Page UserName

    Facebook Likes: <?php echo fb_count('google');?>

It’s very simple, right? If you like this script don’t forget to share with your friends also learn How to: Display twitter followers count on your blog/website If you have any bug report, please share it below.