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 has reached its end of life. Always use the Facebook API when able. Details here. Article remains for information purposes only.
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 N/A.
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
url
url
of the page you're querying for a count. If left blank the current page will be used.n
n="0"
.cache
PHP Function
Used outside of WordPress the following function may be used. Usage requires Simple Cache.
Considerations
- 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.
1Array2(3[http://www.internoetics.com/2012/05/16/count-shares-to-facebook-twitter-linkedin-googleplus/] => Array4(5[share] => Array6(7[comment_count] => 08[share_count] => 599)1011[og_object] => Array12(13[id] => 1015094749574830414[description] => Tweet I've recently consolidated two websites into as a means of managing my time and resources more effectively. The other sites will be revive...15[title] => Count the Number of Shares to Facebook, Twitter, LinkedIn & Google Plus16[type] => article17[updated_time] => 2016-08-25T08:38:28+000018)1920[id] => http://www.internoetics.com/2012/05/16/count-shares-to-facebook-twitter-linkedin-googleplus/21)2223)
Download
No longer available.