Show Facebook Likes as a Number

You might have seen at the top of my website I have a few social media buttons with numbers next to them. This tutorial will show you how to extract the number of Facebook “likes” and allow you to show that number on your website.

Here’s what we’ll be creating (Facebook only):
show facebook likes as a number

Copy and paste this code into header.php, just inside the <body>

// Grab Number of Facebook Likes 
$fc = file_get_contents('');
$pagedata = json_decode($fc);

And then paste this code where you want the number to show up.
This code should be placed within your website’s code and not in a WordPress widget or post.

<?php echo $pagedata->likes; ?>

Need to show the number of Twitter followers as a number? Read this tutorial.

Of course there are a few plugins that do this exact same thing (if you’re using WordPress). The best plugin I’ve found is called Social Count Plus and you can download that here for free.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.