Showing off your FeedBurner subscribers

Another great post from http://yoast.com

Quite a few websites have started to show of their FeedBurner subscriber count with something else than a widget. To do that, you have to be able to grab the number of subscribers through the FeedBurner API.

Now I bet you want to know how! It’s bloody easy in WordPress, just do this:

$fb = get_option("feedburnersubscribecount");
if ($fb['lastcheck'] < ( mktime() - 600 ) ) {
	$snoopy = new Snoopy;
	$result = $snoopy->fetch("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=feedburnerid");
	if ($result) {
		preg_match('/circulation=\"([0-9]+)\"/',$snoopy->results, $matches);
		if ($matches[1] != 0)
			$fb['count'] = $matches[1];
		$fb['lastcheck'] = mktime();
		update_option("feedburnersubscribecount",$fb);
	}
}
echo ''.$fb['count'].' Subscribers can\'t be wrong! Subscribe by <a href="http://yoast.com/email-blog-updates/">email</a> or to the <a rel="nofollow" href="http://feeds.feedburner.com/joostdevalk">RSS feed</a> now!';

Copy, paste, replace feedburnerid with your own FeedBurner ID, and you’re done!

Update: updated the code to include caching, as you might overload the FeedBurner API otherwise.

Update 2: if you get an error saying it can’t find the class Snoopy, add this above the code:

require_once(ABSPATH . 'wp-includes/class-snoopy.php');

Leave a Reply