Display number of Facebook fans in full text on your WordPress blog

Simply paste the following code in any of your theme files, where you want your Facebook fan count to be displayed. Don’t forget to add your page ID on line 2!

<?php
	$page_id = "YOUR PAGE-ID";
	$xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot");
	$fans = $xml->page->fan_count;
	echo $fans;
?>

Thanks to WP Snippets for the recipe!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

Display number of Facebook fans in full text on your WordPress blog

Leave a Reply

Your email address will not be published. Required fields are marked *