X

Get Feedburner Count Using get_transient and wp_remote_get

Snippets by IsItWP

Do you want to get the feedburner subscribers count using functions? While there’s probably a plugin for this, we have created a quick code snippet that you can use to get feedburner count using get_transient and wp_remote_get functions.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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';
   }else{
	$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;
}

Add this code snippet to your WordPress theme file where you want to display the RSS feed subscriber count.

<? feed_subscribers(); ?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 7 best WordPress landing pages plugins that convert and 25 must have WordPress plugins for business websites.

Comments  Leave a Reply

  1. 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?

    Thanks!

  2. should be added echo into the second snippet 🙂

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

  3. 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.

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!
[60% OFF Today!]
[60% OFF Today!]
[10% OFF Today!]
[10% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]