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):
Copy and paste this code into header.php, just inside the BODY tag;
<?php // Grab Number of Facebook Likes $fc = file_get_contents('http://graph.facebook.com/http://www.facebook.com/YOUR_CUSTOM_FACEBOOK_URL_HERE'); $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.