Home / functions.php / Get feedburner count using get_transient and wp_remote_get
  • How to Get feedburner count using get_transient and wp_remote_get


    Adding this snippet to the functions.php of your wordpress theme will get your feedburner subscriber count using get_transient and wp_remote_get. Add the second snippet to your wordpres theme in the location you wish to display the RSS feed subscriber count.

    wordpress snippet : PHP

    function feed_subscribers(){
            $feed_url = 'http://feeds.feedburner.com/yourname';
            $count = get_transient('feed_count');
            if ($count != false) return $count;
    	$count = 0;
            $data  = wp_remote_get('http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri='.$feed_url.'');
       if (is_wp_error($data)) {
            return 'error';
    	$body = wp_remote_retrieve_body($data);
    	$xml = new SimpleXMLElement($body);
    	$status = $xml->attributes();
    	if ($status == 'ok') {
    		$count = $xml->feed->entry->attributes()->circulation;
    	} else {
    		$count = 300; // fallback number
    	set_transient('feed_count', $count, 60*60*24); // 24 hour cache
    	echo $count;

    wordpress snippet : PHP

    <? feed_subscribers(); ?>

    ( WordPress codex functions, hooks, in this snippet. )

    wp_remote_get, wp_remote_retrieve_body, _e, is_wp_error, wp,
  • http://www.heptasarim.com Gökay

    I think the second should be as  In that state the snippet doesn’t show anything. Well, in correct state the snippet do count much more than normal count.

  • http://www.heptasarim.com Gökay

    should be added echo into the second snippet :)

    • http://wpsnipp.com Kevin Chard

      just add the second snippet in the location you wish to display the feed count.

  • Justin

    I’m getting this error “SimpleXMLElement::__construct() [simplexmlelement.–construct]: Entity: line 2: parser error : AttValue: ”

    It was working fine but recently it’s throwing up these errors. Any idea?