I need to add some code to my RSS feeds, so I am searching for the RSS Feed .php file so I can add my code. Any help in finding this template file would be greatly appreciated.
3 Answers
To add some tags to the rss2 feed you may use the 3 action hooks that can be found in the wp-includes/feed-rss2.php
rss2_ns : to add a specific namespace
rss2_head : to add tags in the feed header
rss2_item : to add tags in each feed items
For example, let's assume you want to add a copyright in your feed's header using the dublin core vocabulary :
function my_rss2_head(){
echo '<dc:rights>© '.bloginfo_rss('name').'</dc:rights>'.PHP_EOL;
}
add_action( 'rss2_head', 'my_rss2_head');
Feed templates are in wp-includes
folder, files starting with feed-
. As rest of the WordPress core they are not supposed to be modified.
You will need to:
- Determine type of feed you want to modify (usually default RSS 2.0 one).
- Unhook native function that loads feed template, for example
remove_action('do_feed_rss2','do_feed_rss2');
- Create your own feed template.
- Create and hook your own function that will load your template, by analogue with
do_feed_rss2()
( source ).
Alternatively you can use some specific hooks in feed template to add what you want.
Update
As per Otto's comment steps 2 and 4 can be simplified using add_feed()
function ( source ).
-
3A fine answer, but I'd recommend using the add_feed function instead. You can use it to replace a feed as well as add new ones.– OttoFeb 3, 2011 at 8:02
-
@Otto thanks for hint, looked at source and that would be much less cluttered to use indeed– RarstFeb 3, 2011 at 8:18
-
let's say I edit the feed-rss2.php to change some feature in the presented content. How to apply the configurations? I am not seeing any change in the output– MakanDec 26, 2016 at 22:25
Here's a quick guide: http://codex.wordpress.org/Customizing_Feeds
-
Some of the stuff in that article is verrrry old (as per warnings). I'd not rely on it without double checking with other materials and/or source code.– RarstFeb 2, 2011 at 20:01