Home Blog Count Facebook Shares in Plain Text With WordPress Shortcode or PHP

Count Facebook Shares in Plain Text With WordPress Shortcode or PHP


Facebook has always remained relatively open with regard to the access it provides to their (or your) data – either by way of a registered API call or an open graph request. This article will show you how to include the Facebook share count (via unregistered graph access) into a WordPress post or page, or into a PHP application, in plain text.

For the example, we’ll reference the article on Internoetics where the code was first published. The shortcode of [fbcount url=”http://www.internoetic … inkedin-googleplus/”] (snipped ) returns a count of 59.

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.

Shortcode Attributes


The url of the page you’re querying for a count. If left blank the current page will be used.


The result is returned in a number_format by default. To disable, use n="0".


The period for which results are cached. By default results are cached for 12 hours.

PHP Function

Used outside of WordPress the following function may be used. Usage requires Simple Cache.


  • The returned JSON data includes other information that may be of use (including the last update time). The title, description, and other data are sourced from your Object Graph tags. The array below is the response returned for our example URL.


Title: Count Facebook Shares in Plain Text
Description: Count Facebook Shares in Plain Text With WordPress Shortcode or PHP.
Download: Shortcode (V0.2) | WP Plugin (V0.2) | PHP Code (V0.2)

Shortt URL for this post: http://shor.tt/2nLz


Please enter your comment!
Please enter your name here