Use FeedBurner without a plugin

Redirect your RSS Feed Without Using Plugins or Editing .htaccess

| 2 Comments

It is pretty common for bloggers to want to use FeedBurner to handle their RSS feeds, because of the additional benefits it offers, such as statistics, automatically adding AdSense ads to the feed and pinging services about your new content.

Traditionally, the advice has been to use the FD Feedburner Plugin, which does the trick just fine, don’t get me wrong. But as you should probably know by now, I prefer to handle such items with functions where possible. Because of the prevalence of people using the Feedburner plugin, it wasn’t easy to find too much information on this subject, but after doing some searching, I was able to nail down enough to put together my function which redirects all readers to my FeedBurner feed.

It would be a simpler function if not for the fact that you have to check whether the user-agent is FeedBurner. This is because you have to allow FeedBurner through to your site without being redirected, so that it can actually look at your content, while keeping the redirect in place for everyone else.

At any rate, without any further ado, here is the function, which I drew up with the help of Erik Shultz. Just drop it into your functions.php file and you’ll be set – just be sure to change the FeedBurner URL to that of your own feed!:

// Redirect RSS to FeedBurner //

function diww_rss_feed_redirect() {
    global $feed;

    $new_feed = 'http://feeds.feedburner.com/wanderingbrit';

    if (!is_feed()) {
            return;
    }
    if (preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])){
            return;
    }

    if ($feed != 'comments-rss2') {
            if (function_exists('status_header')) status_header( 302 );
            header("Location:" . $new_feed);
            header("HTTP/1.1 302 Temporary Redirect");
            exit();
    }
}

add_action('template_redirect', 'diww_rss_feed_redirect');

Categories: Code & Snippets | Permalink

What next?

Hire me

If you couldn't quite manage this yourself, find it too intimidating, or just don't have the time to do it, you can always hire Dave to do it. Please get in touch so that we can discuss your needs.

Leave a comment

If you have a question, update, or comment about the tutorial, please leave a comment. I try and respond to every comment, though it may take a few days, so please check back soon.

Keep your site backed up, updated & secure

I provide a service called The WP Butler, which helps you stay on top of the maintenance of your WordPress site. Instead of worrying about whether your site is secure, updated and backed up, The WP Butler handles all that for you on a regular basis, so that you can focus on doing what you do best. If you use coupon DIWW, you'll save 15% on our already-low-prices for all maintenance plans.

Author: Dave Clements

Dave Clements has been building websites for close to a decade and in 2010, he formalised that by starting his own company, The UK Edge. He now works on a variety of web projects, from simple tasks like installing a new WordPress site, to consulting on problems, or redesigning his clients' sites. He also runs Do It With WordPress, a site dedicated to providing free tutorials on WordPress. When he's not building your new website, you can find Dave eating Wheat Thins, spending time with friends and family, watching Indie films, fostering kittens from the local Humane Society, listening to some dubstep, dance and electronic rock, and exploring the world.

2 Comments

  1. Hi Dave, thanks for this snippet. One question – are all WP feeds redirected to Feedburner? I mean tags, categories, and comments feed along with the main site feed?

    • Hi Josephine,

      No, this is only for the main feed. You can create extra feeds and send those to FeedBurner as well, but that would be a lot of manual work to create all of those feeds for every category, tag, author etc.

Leave a Reply