Customising a WordPress installation is relatively straight forward—you pick a theme and then tweak it to your satisfaction—you can make that as easy or hard as you like depending on your skills and requirements and it is all fairly well documented. It uses a theme system so that any templates that you place in the theme directory override the default ones, This blog, for instance, has modified versions of the index, page and single templates which determine the content and appearance of the post stream, pages and single posts respectively.
Customising the feed contents and appearance is not so easy. The system includes three hooks which allow additional content to be included—In the case of RSS2 feed they are rss2_ns in the RSS header, rss2_head in the channel content and rss2_item in each item section. These are what podcast plugins use to add in the iTunes XML stuff that they need.
There is, however, no mechanism to remove or modify the existing standard content. What it needs is the ability to override the templates with ones of your own. The relevant template here is wp-includes/feed-rss2.php and it is loaded from the function do_feed_rss2 in wp-includes/functions.php. That default routine looks like this
function do_feed_rss2( $for_comments ) {
if ($for_comments)
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php');
else
load_template( ABSPATH . WPINC . '/rss2-atom.php' );
}
What is needed is this which can be put in your theme’s functions.php
function custom_feed_rss2( $for_comments ) {
if ( $for_comments ) {
if ( file_exists(STYLESHEETPATH . '/feed-rss2-comments.php'))
load_template( STYLESHEETPATH . '/feed-rss2-comments.php' );
else
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
}
else {
if ( file_exists(STYLESHEETPATH . '/feed-rss2.php'))
load_template( STYLESHEETPATH . '/feed-rss2.php' );
else
load_template( ABSPATH . WPINC . '/feed-rss2.php' );
}
}
Then replacing the default routine with the new one using
remove_action('do_feed_rss2', 'do_feed_rss2');
add_action('do_feed_rss2', 'custom_feed_rss2');
then the copies of the templates in your theme directory will be picked up if they exist and defaults used if not. Similar things can be done for the rdf, rss and atom feeds but I don’t use them; note: however, that if you have removed things because you don’t want them revealed to the world then you need to do it on all available formats because they are all available whether you advertise them or not.
What do I use it for? well I want to put the event date into some posts rather than the posting date and also I have a need to suppress comment feeds altogether on one site.






Webmaster
Hi,
Thanks for the example above. I want to add to the existing content of my
rss feed through an addfilter function in my functions.php file but I am not sure how to do this. Is it even possible?
I basically need to add a tag within which is called which calls another function
Thanks in advance
I meant to say tag within ‘item’ which is called ‘imsrc’
You will need to
add_action(‘rss2_item’, “your_routine’);
not add_filter to do this and provide the routine in functions.php to generate the additional tag. Your routine will get called at the start of every item (or end, I can’t remember). But be aware that you will break the standard XML doc format if you do this and some RSS readers may object and not render it at all. Even if they do they won’t know what to do with your new tag.
My favourite Podcasting plugin, Podcasting Plugin by TSG, doesn’t help matters here by directly calling do_feed_rss2 (podcasting-feed.php line 48). I have had to hack the source to get around this one. Surely there must be a better way for them to create the feed type which acknowledges the local changes made.