Snippet: Get your number of Facebook fans

Add following code where you want to display your fans

Usage

<? echo get_my_fb_fans($my_page_id); ?>

Add following snippet to “functions.php”

Snippet

function get_my_fb_fans($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;
    return $fans;
}

Result

Display number of fans your facebook page has on your website with this simplest function.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>