Tradu articolul în română (Google Translate)

Note: The article below has been written more than 8 years ago!

Facebook: WordPress code to display the number of comments / shares / likes for the current blog post for administrators only


Let’s say you have a Facebook page and you want to know how many likes / shares / comments does the current blog post has. I made a script, based on this article, which allows you so see how many likes / shares / comments a blog post has.

It will give you an information like this:


How to do it? You should add the following code:

if( current_user_can('administrator') ) {

$source_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$rest_url = "".urlencode($source_url);
$xml_response = file_get_contents($rest_url);
$xml_record = simplexml_load_string($xml_response);
$fb_share_count = $xml_record->link_stat->share_count;
$fb_like_count = $xml_record->link_stat->like_count;
$fb_comment_count = $xml_record->link_stat->comment_count;
$fb_total = $xml_record->link_stat->total_count;
echo '<br/><br/><b>Administrator</b> information:<br/>';
echo 'Facebook Shares: '.$fb_share_count.'<br/>';
echo 'Facebook Likes: '.$fb_like_count .'<br/>';
echo 'Facebook Comments: '.$fb_comment_count .'<br/>';

in your single.php file (or wherever else you need it), to have it display the information as in the picture above.

Change the condition to

if( (current_user_can('administrator')) && (is_single()) ) 

, if you want to add the code to only launch if the current page is single (so, you can thus put the code in header.php or in footer.php or in sidebar.php).

Last modified on: 2015.11.29, at: 18:38.

Share on WhatsApp

Lasă un comentariu

Rules for commenters »

Puteți folosi Gravatar pentru a adăuga avatar (imagine comentarii).

Acest site folosește Akismet pentru a reduce spamul. Află cum sunt procesate datele comentariilor tale.