How to Display Facebook Page Review Count Using PHP

using PHP and the Facebook Graph API

Blogs deliver solutions to your problems

The other day I had an issue while developing a client’s new website. The issue was with an embedded Google Street View virtual tour I’d shot for them previously . When the user scrolled over the embedded element it zoomed in and out automatically. This was very annoying and created an unacceptable user experience. I knew how to solve this issue when it occurred on a Google Map, but I was unaware of a solution for the embedded virtual tour.

The annoying behavior can be experienced in the embedded tour below.

I began my search for a solution by Googling “disable zoom on google street view embeds”. Here are the results.

Google search results for disabling embedded street view.

Jonny Jordan is a web developer in Belfast, Ireland. His result jumped out at me because it had eight 5 star reviews, plus it was a blog article and not just answers to user questions on Stack Overflow. I assumed there would be a better explanation coming from a blog and my assumption was correct! Here’s the same embedded iframe with Jonny’s solution.

Ratings and SEO

This blog post really helped me out. So I decided to peruse the rest of Jonny’s site and see what other juicy tidbits lurked inside. I spent a good amount of time on his blog and enjoyed reading about the perspectives of a developer working in Belfast.

Then I got to thinking, why did I choose this blog? And the answer is very simple, the ratings made me do it! aggregate rating markup in Google search results.

We all want to do business with people we trust, but if we don’t know them personally, we want to know that others trust them and have gone so far as to publicly endorse them by writing an online review about their product or service.

I ask my clients to please leave me a 5 star review on Facebook and Google, assuming they feel like my services were worth 5 stars, because I know that reviews are a significant ranking factor in Google’s local search algorithm.

Because I’m the new kid on the block so to speak, and don’t have a ton of authority content yet, I need every endorsement I can get to make sure I show up in the local SERPs!

But reviews on Facebook and Google aren’t really helping my blog posts and web pages show up in the SERPs. So the burning questions becomes,  “How did Jonny do it?”.

Schema, Semantics & Structured Data

Ask your developer and SEO professional what they think about schema, semantic HTML and structured data. If they look at you like a deer in headlights, or are ambivalent to the topics, fire them.

This is not a passing fad. If Google tells you this is what they want to see, you best sit up and listen, because if Google can’t find you, neither can your customers.

In a nutshell, structured data are additional attributes added to your HTML markup that provides a high level of organization and added context to the content of your webpage. Structured data essentially allows you to “talk” to the search engines and tell them what your page is about, rather than making them (hopefully) figure it out themselves.

So how did Jonny get me to click on the link to his site? By adding structured data in the pages’ footer.

Schema aggregate rating markup and the resulting content.

That little bit of extra markup has now resulted in me not only perusing Jonny’s site, its led to me writing this blog post and providing a high quality contextual backlink to his site.

If you don’t know, contextual backlinks are SEO gold because they’re essentially votes of confidence that the linked content is an authority on the subject matter.

How to add your Facebook review count to your WordPress website’s footer.

I used this example to explain the benefits of structured data during a meeting with an advertising and marketing company. They brought up a good point about where were these 8 actual votes of 5 star confidence? Not knowing the answer, I decided to create a solution. Here’s what I did.


  • You have a WordPress website.
  • You’re using a child theme or custom built theme (so your changes won’t be overwritten during an update).
  • You can access your theme files.
  • You’re comfortable coding with PHP.
  • You have at least 1 review on your Facebook Business page.
  • You have a Facebook App for your Business page and corresponding App ID and App Secret.

If you aren’t sure about any of the assumptions, “Google it dude!”

3 Steps to a dynamic review count

You can add your actual review count and have it update automatically when someone leaves a new review in three simple steps. The files we will be modifying to achieve this setup are…

  1. >functions.php
  2. >footer.php
  3. >wp-config.php


This file contains all the configuration settings for your WordPress install. It is NOT overwritten when you update WordPress core. This is the file that contains your database login credentials and is a good place to store other sensitive data like the access token we’ll use to authenticate our Facebook session. Add this piece of code to your wp-config.php file and be sure to include your app’s unique ID and Secret.


In your child or custom theme’s functions.php file add this bit of code.


Now just add this little bit where you want the output to render.

The Results

Facebook review count code and output.

One of the things I did different was to add a clickable link to the review count text so that users could go to my page and see the actual reviews.

Shortcomings and Future Improvements

Though I was pleased with the results there is an obvious shortcoming that I’ve yet to find a solution to. While the total count is always going to be up to date, what about the aggregate rating? If you’ll notice, that value is hard coded into the script so it will never change unless the script is changed. In short, someone could leave me a 1 star review (ain’t gonna happen) thus impacting my current 5 star rating and it would not be reflected in the page footer!

The crux to this solution is the need for a page access token to retrieve the individual review rating, text, and reviewer. A page access token is granted during the login process and I really don’t want visitors to the site to be forced to login just so I can exchange their user token with a page token and deliver dynamic rating results.

I’m sure there’s a viable solution, I just haven’t found it… yet 🙂


So there you have it, three simple steps to dynamically add your Facebook review count to the footer of your WordPress website, complete with semantic, structured data using the language.

If you enjoyed reading this post, think I’m worth 5 stars, and would like to see this script in action, check the current count by visiting the page’s footer, then follow this link to my Facebook review page and leave me a 5 star review. Then check back and see how YOU have made a difference in this developers life!

Thanks for reading! Until next time…

William Conkwright

Will Conkwright is the owner at Circle Squared Publishing, LLC, a photographer, writer, full stack web developer, Google Street View Trusted Photographer, competitive cyclist, endurance athlete and adventure junky who loves riding motorcycles.

Subscribe for premium content

Subscribers receive members only content delivered straight to their inbox. Admission is free. Inspiration is priceless.

Related Articles


Dinghy valves and the caps that accompany them

Captain Zoey Zaleta of Offshore Rafting So you think... Read More

Photography | Tutorials

Photographing the 2017 Croaker Festival

my approach to event photography My Approach to Event... Read More

Tutorials | Writing

How to Get Public Data from Facebook with PHP

This article will teach you how to access public... Read More