2

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 3

2

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>&copy; '.bloginfo_rss('name').'</dc:rights>'.PHP_EOL;
}
add_action( 'rss2_head', 'my_rss2_head');
2

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:

  1. Determine type of feed you want to modify (usually default RSS 2.0 one).
  2. Unhook native function that loads feed template, for example remove_action('do_feed_rss2','do_feed_rss2');
  3. Create your own feed template.
  4. 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 ).

3
  • 3
    A 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.
    – Otto
    Feb 3, 2011 at 8:02
  • @Otto thanks for hint, looked at source and that would be much less cluttered to use indeed
    – Rarst
    Feb 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
    – Makan
    Dec 26, 2016 at 22:25
-1

Here's a quick guide: http://codex.wordpress.org/Customizing_Feeds

1
  • 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.
    – Rarst
    Feb 2, 2011 at 20:01

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.