Redirect Your WordPress Feeds to Feedburner

How to Redirect Your WordPress Feeds to Feedburner

in RSS Feeds
Google+ LinkedIn

Google Feedburner is a great tool for managing your feeds and I am sure many of you have already been using it. Not only does it make it easier for people to subscribe to our outbound communication channels, Feedburner also gives us the analytical tools to dig into the data. Now if you have setup your Feedburner feed, you might want to redirect your WordPress feeds to Feedburner. I have seen lots of website owners simply edit header.php file and paste the Feedburner feed URL in their theme, which is the wrong way. In this article we will show you how to redirect your WordPress feeds to Feedburner easy way. You might also want see our previous article to display featured post thumbnails in WordPress feeds.

There are plenty of WordPress plugins available to redirect your WordPress feeds to Feedburner. But they are all just unnecessary plugins because you can redirect your WordPress feed to Feedburner by adding just 4 lines of code in your website. Yes, it’s that simple. There are two ways to redirect your WordPress feeds to Feedburner. Both of these redirects feed requests to your feedburner URL. Not to mention, you need to change http://feeds.feedburner.com/WPCodeSnippet to point your own Feedburner address. Otherwise you’ll be redirecting your feed to our Feedburner account.

With WordPress

Paste this WordPress code snippet in your theme’s functions.php file.

// redirect your wordpress feeds to feedburner
function wcs_redirect_feeds() {
  if ( is_feed() && !preg_match( '/feedburner|feedvalidator/i', $_SERVER['HTTP_USER_AGENT'] ) ) {
    header( 'Location: http://feeds.feedburner.com/WPCodeSnippet' );
    header( 'HTTP/1.1 302 Temporary Redirect' );
  }
}
add_action( 'template_redirect', 'wcs_redirect_feeds' );

With .htaccess

Simply add the following code in .htaccess of your website.

# redirect your wordpress feeds to feedburner
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
    RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
    RewriteRule ^feed/?([_0-9a-z-] )?/?$ http://feeds.feedburner.com/WPCodeSnippet [R=302,NC,L]
</IfModule>

Note that .htaccess has the potential to bring your site down. Even a small typo may end up in 500 Internal Server Error. So, before editing your .htaccess, take a backup of the current file and keep it handy. In case anything goes wrong, you can restore the original .htaccess file.

Share the love

If you like this snippet, share it with others!

Leave a Reply

Your email address will not be published. Required fields are marked *