Home Blog Count Facebook Page Likes with WordPress Shortcode or PHP

Count Facebook Page Likes with WordPress Shortcode or PHP

Facebook Page Likes

Note: With changes to Facebook’s API, the code on this page may not work. We’ll review it soon.

This article will show you how to include your Facebook page likes in plain text with WordPress shortcode, a PHP function, or with our WordPress plugin. This is the first of quite a few articles that’ll show you how to include the counts of various social networks in your websites via various means. This function requires that you register a Facebook application (don’t worry, it’s easy). Follow the steps as described here.

As an example, the count for our Flight Facebook page, using the shortcode of [fblikes id="flightorg"], is Unavailable (code to be updated) (bolding is mine). We’ve cached the result for 12 hours and applied number formatting by default (details below). The sad count for BeliefMedia’s page is Unavailable (code to be updated) (we’re yet to promote it in any way).

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

WP Plugin

If you download our plugin you’ll find the menu to update all options under Tools -> BeliefMedia Facebook Counts.

Count Facebook Page Likes with WordPress Shortcode or PHP

Find options at Tools → BeliefMedia Facebook Counts.
As of V0.3, the APP ID is replaced by an access token.

Any attributes supplied in your shortcode will overwrite the options saved to your database (normally just the Facebook page ID).

PHP Function

Used outside of WordPress, the following PHP function may be used. Usage requires Simple Cache (to cache data and avoid repeated and lengthy requests to Facebook).

Arguments are passed to the function in an $args array.


  • You might consider rendering the result as an image. There are any number of ways of achieving this – notably with GD or ImageMagick. This very simple example renders each digit as an image.

  • Using our textbox shortcode you can include the count in a nicely formatted manner.

Join Unavailable (code to be updated) others on our very lonely BeliefMedia FB page


Join Unavailable (code to be updated) others on our FB page for regular and free WP Code & Plugins.

  • If you download the plugin we’ll provide you with update notifications via your dashboard. We expect to build lots of features into this plugin, such as the image feature described above.


Title: Count Facebook Page Likes with WordPress Shortcode or PHP
Description: Display a count of FB page likes in plain text with shortcode. Requires the creation of an application.
Download: Shortcode (V0.3) | WP Plugin (V0.3) | PHP Code (V0.3)

■ ■ ■

Interested in WordPress and Web Design? Subscribe to our list and we'll send you subscriber-only tools and plugins

Short URL for this post: http://shor.tt/19ov


  1. Thanks a lot for this! I have been searching for a long time and there’s quite a lot of codes and tutorials on the internet, but only your code worked and didn’t give me an error or some warning. Perfect 🙂


Please enter your comment!
Please enter your name here