Recently I was faced with the task to create various formats of the WordPress feed. My initial thought was to create a new “page” and use that as the feed. So you would call something like domain.com/custom-feed/ Then I found the add_feed() function: I could not find proper documentation for the function in the Codex, but here is an attempt to explain how it works. This make is easier to call domain.com/feed=custom-rss to get the custom RSS feed.
About add_feed
This function takes two parameters: Feed Name, and Callback Function. The callback function will handle the feed template, and will have access to Loop.
Timing matters The add_feed function MUST be called after WordPress is completely initialized. In my tests. I found it to work in the init action hook.
The code
function custom_rss_feed()
{
add_feed('custom-rss', 'custom_rss_feed_template');
}
add_action('init', 'custom_rss_feed');
function custom_rss_feed_template()
{
load_template( TEMPLATEPATH . 'custom_rss_feed.php');
}
The code explained
First, we add an action to call the custom rss function during the init. Then, we define the new custom rss feed using add_feed. This feed will then give use a ‘custom-rss’ feed. The custom_rss_feed_template is called when feed=custom-rss is specified. The custom_rss_feed_template function calls your template file.
Creating the template
At this point, all you still need to do is to create the custom template. The easiest way to go about this is to copy the wordpress/wp-includes/feed-rss2.php template to your theme directory. rename it to custom_rss_feed.php and start modifying the file to your needs. All of the WordPress functions will still work, because you are still in the Loop.
Afterthought
You can then take it a step further and create rewrite rules so that you don’t need the query string feed=custom-rss but instead something like feed/custom-rss/