Show Facebook Likes with PHP

Posted by: Alex on June 25, 2013

Here’s a simple way to show a facebook page’s current number of likes, it combines JSON and PHP, very simple! Can be used Facebook Profiles/Pages, as well as edited to work for general links and websites.

function fb_likes_count(){
$data = json_decode(file_get_contents(""));
echo $data->likes;}


At the time of writing that will output “91” (likes currently) straight away, just call the function fb_likes_count(); where you want it echo’d.
The number of likes on my Facebook page is: <?php fb_likes_count(); ?>

There is actually a lot more data available within that JSON object, here are the values returned that you can also hook onto if you wish:

   "about": "guwii - Web Design Agency in Cardiff.",
   "category": "Computers/technology",
   "is_published": true,
   "talking_about_count": 60,
   "username": "guwii",
   "website": "",
   "were_here_count": 0,
   "id": "114477908707450",
   "name": "guwii",
   "link": "",
   "likes": 91,
   "cover": {
      "cover_id": 199485470206693,
      "source": "",
      "offset_y": 0,
      "offset_x": 0