Super Plugin Sale! Your Choice: BOGO or 30% Off »
Web Dev + WordPress + Security

PHP and JavaScript Fallbacks for Your Public Feedburner Count

With the recent Feedburner service outage, many sites across the Web experienced severe drops in their Feedburner subscriber counts. Apparently, Google is requiring all Feedburner accounts to be transferred over to Google by the end of February. In the midst of this mass migration, chaotic subscriber data has been reported to include everything from dramatic count drops and fluctuating reach statistics to zero-count values and dreaded “N/A” subscriber-count errors. Obviously, displaying erroneous subscriber-count data on your site is not a good thing. Fortunately, there are several ways to ensure that this doesn’t happen.

Feed Count Down

Over at CSS Newbie, author Rob Glazebrook weighs in with an excellent point about covering your bases when displaying your Feedburner subscriber count. As explained in the article, Feedburner’s handy API makes it easy to tap your data and display your subscriber count on your blog. Despite its best intentions, however, Feedburner occasionally returns inaccurate data or even no data at all for the subscriber count. For those of us who care about the accuracy of our publicly displayed feed statistics, displaying information like this on your site is simply unacceptable:

Join N/A awesome subscribers!

..or perhaps even worse:

Join 0 awesome subscribers!

Ugh. Clearly not the way to leave a good impression and encourage visitors to subscribe to your feed. Fortunately, there are several ways to deal with this situation, including avoiding the public display of your subscriber count or even finding an alternative to Feedburner. Yet for those of us who insist on proudly displaying our subscriber numbers, there are a couple of good methods for providing a fallback for your public Feedburner subscriber count.

As with Rob and his site, I am also using Francesco Mapelli’s excellent Feed Count plugin1 here at Perishable Press. The plugin is a snap and provides all the functionality needed for customized text-display of your subscriber count. With the plugin’s text output of your feed stats, it is possible to echo virtually any message or markup you wish to embellish with your data. Unfortunately it doesn’t do anything for you when the Feedburner number is unavailable or otherwise inaccurate.

1 Editor’s note: plugin link removed because the site is reported as an “attack site” by Google. For an alternate version check out this post at

JavaScript and jQuery Fallback

The JavaScript solution provided by Rob looks like this:

$spans = document.getElementById('subbox').getElementsByTagName('span');
if($spans[4].innerHTML=="N/A" || $spans[4].innerHTML=="0") {
	$spans[4].innerHTML = "thousands of";

This snippet of JavaScript evaluates the Feedburner count value of the Feedcount plugin. If either “N/A” or “0” is detected for your subscriber count, the script replaces the erroneous value with “thousands of” instead.

Rob also provides a jQuery-based fallback method:

if($(".subscribers").html() == "N/A" || $(".subscribers").html() == "0") {
	$(".subscribers").html("thousands of");

..which basically does the same thing as the more elaborate JavaScript method, only in a more straightforward and elegant fashion. Be sure and see the original article for more information on either of these JavaScript techniques.

A Better Solution

Of course, relying on a client-side technique such as JavaScript for a fallback solution is less than an ideal solution. Unfortunately, a significant percentage of users are visiting your site without JavaScript. Many mobile devices do not have JavaScript, many public and corporate browsers disable JavaScript, and many security-minded individuals disable it on their personal machines.

A better approach is to use a server-side language such as PHP to craft a more reliable solution. By generating the proper feedcount value before the data is sent to the browser, we ensure that all visitors see the correct subscriber information, regardless of browsing device and whether or not JavaScript is available.

PHP Fallback

Here is the PHP script that I am using here at Perishable Press:

<?php function feedcount_fallback() {
	if(function_exists('fc_feedcount')) {
		$count = ob_get_contents();
		if($count == 'N/A' || $count == '0') {
			echo 'many other';
		} else {
			echo $count;
	} else {
		echo 'many other';
} ?>

Place that code into your theme’s functions.php file and then replace the default Feed Count function call with this in your theme’s template file:

<p>Join <?php if (function_exists('feedcount_fallback')) feedcount_fallback(); ?> awesome subscribers!</p>

Once in place, this code will output one of the following messages, depending on availability of accurate Feedburner subscriber-count data:

  • “Join 243 awesome subscribers!” — outputs correct count value when available
  • “Join many other awesome subscribers!” — outputs alternate value when count value is returned as either “N/A” or “0”

How does this script work? Basically, we are using PHP’s output buffering functionality to capture the output value of the fc_feedcount() function and compare it to the two possible error values (“N/A” and “0”). When the error values are detected, the alternate, fallback message is displayed; otherwise, the function displays the actual count value. Plus, as an added bonus, the function covers your bases by outputting the fallback message in the event that the Feed Count plugin itself should fail. This method ensures proper subscriber count display without relying on the availability of JavaScript, accuracy of Feedburner data, or even the functionality of the Feed Count plugin!

Bonus Tip

Of course, there are many ways to use and modify this script to suit your needs. For example, if you are providing a subscriber-count verification link, you may want to do something like this instead:

	<a href="" 
	   title="Verify my subscriber count via Feedburner" 
		Join <?php 
			  if (function_exists('feedcount_fallback')) 
		awesome subscribers!

Live Long and Prosper

Thanks to Rob for writing his article on this topic. Without it, I never would have thought to share this technique. Also thanks to Francesco Mapelli for his awesome Feed Count plugin. And thanks to you for reading the article and maybe even sharing your thoughts with us (hint, hint!).. ;)

[ January 2009 and seven days of heavy fog ]

About the Author
Jeff Starr = Web Developer. Book Author. Secretly Important.
WP Themes In Depth: Build and sell awesome WordPress themes.

8 responses to “PHP and JavaScript Fallbacks for Your Public Feedburner Count”

  1. Sweet i’ll add this to my things to add to the ultimate theme ;)

  2. Iacob Ionut - Freelance Website Design 2009/01/25 2:56 pm

    Ha … I used something like this one of my older sites , but instead of echoing “many other awesome…” I used ” Hundreds and counting … “.

  3. Have never used Feedburne ryet but thanks for sharing this because one day i might!

  4. You’ll never stop to surprise me, Jeff!!

  5. @Donace: Hmmm.. funny, I happen to be working on a new theme as well ;)

    @Iacob: That’s just as good — I tried to keep it as unassuming as possible.

    @Vic: Sounds great — thanks for the comment!

    @Bleyder: I certainly hope not! :)

  6. you always are Jeff…always :p

  7. Tyler Abell 2009/12/11 1:07 pm

    If i wanted to include the php script on a page, such as my content page, and I have to post it trough the wordpress editor, how would I do that?
    Do I have to create some sort of short code and then in the editor inset [feed-count]


  8. Hi Tyler, you may be able to rig something like that up with shortcodes, OR, and another option is to use the PHP-exec plugin (I think that’s what it’s called) to enable PHP functions directly in post content.

Comments are closed for this post. Something to add? Let me know.
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
GA Pro: Add Google Analytics to WordPress like a pro.
Crazy that we’re almost halfway thru 2024.
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.