In my theme i use add_theme_support( 'automatic-feed-links' ); to enable the rss links.

But i want to create an option to use Feedburner for the main rss feed, my problem is that i don't know how i can hook in and change the default rss link?

  • I usually use a simple plugin to redirect or do it in .htaccess to the same effect. Is that not acceptable? Feb 16, 2012 at 12:38
  • Have you tried the Feedburner plugin?
    – mor7ifer
    Feb 16, 2012 at 12:41
  • I guess it is acceptable to use .htaccess, but it makes it harder for someone with less knowledge to do it if they use my theme. I will check out the plugins :)
    – andeersg
    Feb 16, 2012 at 12:46
  • Ah, I see what you are doing. IMO, I don't include feedburner options within a theme. I leave that up to the end user. Is this still valid? justintadlock.com/archives/2008/12/15/… Feb 16, 2012 at 13:50
  • I see your point, but i think it's nice to have the opportunity to easily add feedburner. But i want it to be optional. I will check your link :)
    – andeersg
    Feb 16, 2012 at 15:49

1 Answer 1


You can take advantage of the template_redirect hook and redirect any request to the WordPress feed to a URL that you define.

The most important thing to consider is the case when users are attempting to access the feed itself. In that case, you'd obviously not want to do any redirection.

Here's how you can do that:

function example_redirect_feeds() {

    // We only want to redirect if we're accessing the feed.
    if(is_feed()) {

        // Define the URL's to which we'll redirect...
        $feed_url = 'YOUR_FEED_REDIRECT_URL';
        $comment_feed_url = 'YOUR_COMMENT_FEED_REDIRECT_URL';

        global $feed, $withcomments;

        // If the user is requesting to access the comment feed, redirect...
        if($feed == 'comments-rss2' || $withcomments) {

            header("Location: " . $comment_feed_url);

        // ...otherwise, go ahead and redirect to the feeds you defined above.
        } else {

            // We need to capture all different feed types
            switch($feed) {

                case 'feed':
                case 'rdf':
                case 'rss':
                case 'rss2':
                case 'atom':

                    header("Location: " . $feed_url);



            } // end switch/case

        } // end if/else

    } // end if

} // end example_redirect_feeds
add_action('template_redirect', 'example_redirect_feeds');

If you're planning to redirect feeds for comment streams, too then you'll need to add that to this function, as well.

Note that I'm unsure if using die is the best practice here - it gets the job done, but "feels" a bit weak (though it is better than wp_die since that function is designed to actually return an error message - not just halt execution).

  • Thank you for a good explanation. I will try your solution :)
    – andeersg
    Feb 16, 2012 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.