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 Share Count

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.

Note: This hack may have reached its end of life. Always use the Facebook API when able.

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 0.

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)

■ ■ ■

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/19oL


Please enter your comment!
Please enter your name here