Home » Php » php – Facebook Like Count

php – Facebook Like Count

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’ve successfully integrated a Facebook Like button to WordPress based website. The Facebook Like button is shown only on single posts. However, I would like to output how many times a post is being liked on the front page of my site without showing the actual like button. A simple number output is what I’m after.

I’ve been reading Facebook documentation as well some tutorials that partly deal with this issue, but haven’t got anywhere so far.

How to&Answers:

Paste this function in your theme functions.php file and save the file.

function bfan() {
    $pageID = 'Page ID/Page Vanity URL';
    $info = json_decode(file_get_contents('http://graph.facebook.com/' . $pageID));
    echo $info->likes;
}

Then you can call the function.

You will need to know your facebook page ID or facebook page name,then just substitute it in the code above.

Hope this helps you out.

Answer:

Facebook has an API for finding out how many Facebook shares (likes etc.) a page has:

http://graph.facebook.com/?ids=https://stackoverflow.com/

Answer:

I found here a simple and great solution: link

Answer:

If you want see the evolution of your Top Social Stories in your WordPress, you can use this plugin that tracks data from Facebook, Twitter and Google+ for each post and globally for all the links of your blog and export these data also in custom field to use them in your theme.

UPDATE: this plugin now tracks also Pinterest, Linkedin and Vkontakte and has many new features.