Previously I was using FQL for this, but this is deprecated as of v2.1 and I\'m moving over to v2.3 using the graph edge \"likes\".
Here is my URL:
h
Thanks @NativePaul
I spent almost two days to find a solution to get the Facebook Fan Page likes counter in numeric value to a shortcode. So I have amended a code I got from this link: http://www.internoetics.com/2015/07/13/display-number-facebook-page-likes-wordpress-php/
And amended it to work with the fan_count fields and here is the code for your reference:
/*
Display the Number of Facebook Page Likes in Plain Text with WordPress Shortcode (and PHP)
Shortcode: [fbpagelikes id="" appid="" appsecret="" cache="" n="1"]
*/
function internoetics_fb_pagelikes($atts) {
extract(shortcode_atts(array(
'id' => 'kenryscom',
'appid' => 'xxxxxxxxxxxxxxxx',
'appsecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'n' => 1,
'cache' => 3600 * 24 * 1
), $atts));
$fbcounthash = md5("$url.$cache.$appid.$appsecret.$n");
$fbcountrecord = 'fblikes_' . $fbcounthash;
$cachedposts = get_transient($fbcountrecord);
if ($cachedposts !== false) {
return $cachedposts;
} else {
$json_url ='https://graph.facebook.com/' . $id . '?fields=fan_count&access_token=' . $appid . '|' . $appsecret;
$json = file_get_contents($json_url);
$json_output = json_decode($json);
if($json_output->fan_count) {
$fan_count = $json_output->fan_count;
if ($n) $fan_count = number_format($fan_count);
set_transient($fbcountrecord, $fan_count, $cache);
return $fan_count;
} else {
return 'Unavailable';
}
}
}
add_shortcode('fbpagelikes','internoetics_fb_pagelikes');
You have to add the above code to the theme functions file and use the Shortcode anywhere as mentioned in the beginning of the code.