How to change your feed links without using htaccess

So, you’ve set up a Feedburner account, but you don’t know how to point your feeds to it correctly. The best method is to change this within your .htaccess file, but some bloggers might not be very comfortable fiddling with it or might not even be able to access it through FTP (depending on hosting environment).

What I’ll show you is a simple way to change all of your feed links without having to dig through a bunch of code in all of your theme and plugin files. This is also a great method for theme authors that allow users to input a custom feed URL through a theme settings page.

Before moving on, I do recommend using Perishable Press’ method of redirecting feeds through htaccess.

Using your theme’s functions.php to change feed links

The first thing we need to do is open our theme’s functions.php file.

Then, you need to open a set of PHP tags:

<?php

What we’ll do from this point is change our main feeds to point to our Feedburner account:

add_filter('feed_link','custom_feed_link', 1, 2);

function custom_feed_link($output, $feed) {

	$feed_url = 'http://feeds.feedburner.com/justintadlock';

	$feed_array = array('rss' => $feed_url, 'rss2' => $feed_url, 'atom' => $feed_url, 'rdf' => $feed_url, 'comments_rss2' => '');
	$feed_array[$feed] = $feed_url;
	$output = $feed_array[$feed];

	return $output;
}

That points all of our main RSS and Atom feeds to Feedburner. However, you might not know that your author, category, tag, and search archives all have feeds associated with them. You can change those links as well.

add_filter('category_feed_link', 'other_feed_links');
add_filter('author_feed_link', 'other_feed_links');
add_filter('tag_feed_link','other_feed_links');
add_filter('search_feed_link','other_feed_links');

function other_feed_links($link) {
	$link = 'http://feeds.feedburner.com/justintadlock';
	return $link;
}

Don’t forget to close off your PHP:

?>

Final thoughts on feeds

As I’ve said, the htaccess method is the best way to ensure your feeds are being directed to the proper place. The method described above does nothing more than change the output of your feed links.

The most practical application of this is for theme authors to help their users by adding in this option on the theme settings page.

And yes, I know there are plugins that handle feeds, but I don’t much see a point in using a plugin for simple tasks.

Also, check out this great collection of 10 RSS tips for WordPress by Jean-Baptiste Jung.