I want to add a custom feed on my site for SEO purposes.

So, I first copy the /wp-includes/feed-rss2.php file into my theme folder and renamed it. I figured I'll be able to easily edit my feed.

Then I add this code :

function yandex_news_feed() {
load_template(TEMPLATEPATH . '/yandex-news.php'); 

function yandexnews_add_feed() {
add_feed('do_feed_yandexnews', 'yandex_news_feed');

add_action('init', 'yandexnews_add_feed');

I tried with many many ways and read a lot of documentation (almost always the same, a lot of people add rewrite_rules to the code but that's not the issue here) and source for add_feed tell that rewrite rules are taken care of.

But, anyway, that's not working at all, weither i'm doing http://infoglam.exigences.biz/?feed=yandexnews or http://infoglam.exigences.biz/feed/yandexnews ; that's the same : blank page, empty, nothing.

Please note that if use volontarily incorrect name like http://infoglam.exigences.biz/?feed=yandexnews5 I get a error ERROR: yandexnews5 is not a valid feed template. so it looks loke the feed name is registered, but the template isn't executed.

I have check permissions on template file, i tried with and without do_feed_ ; I tried with include instead of load_template()

I guess I could at the end use a template page with a blank page on the admin, but I find this not elegant - if efficient and quick. I will use several feeds on the site and I don't really want to deal with blank pages, and if I use the theme elsewhere I will need to create pages again, it will be best to have it concelead with the theme.

I guess the problem could be with the loading of the template but now I'm completely lost and cannot find where i'm doing it wrong.

Could someone give me a hand please ?

  • Maybe I need to make some query first ? ...
    – Simon
    Commented Mar 22, 2012 at 14:38
  • Now something very weird : to check I have added this code which worked as a test. After I remove the code from functions.php ... the special feed still working (for 20 mins so it's not a caching issue). I'm getting mad.
    – Simon
    Commented Mar 22, 2012 at 15:21
  • add_feed Does not take care of fetching posts for you. You'll need to do that on your own. Also, you need to flush your rewrite rules to make it work. Commented Mar 22, 2012 at 22:54
  • No I finally get it : add_feed is like adding a new filter name for displaying content, based on url (the normal query), that will use the designated template. Right now, I don't flush the rewrite rule because I don't care using the ?feed= syntax (which I find more clear to separate from user content). Tx.
    – Simon
    Commented Mar 22, 2012 at 23:00

1 Answer 1


Code is working :

add_feed('myfeed_rss2', 'my_feed');

function my_feed() {
add_filter('pre_option_rss_use_excerpt', '__return_zero');
load_template( TEMPLATEPATH . '/custom-feed.php' );

RSS is contextual : if I add ?feed=myfeed_rss2 after index url, this will tell WP to display the content of the home with the template custom-feed.php - it's more a filter than anything else. I was considering RSS from a wrong point of view.

If I add ?feed=myfeed_rss2after a category page url, it will display the category page with the template custom-feed.php.

I didn't find a way still to alter the query from the template, this should be done differently, i.e. creating a special page in theme and then calling the RSS template upon it (for example, having a RSS feed 50 article long).

The RSS template is only the strict XML structuration of the content, with the ability to use PHP code to add information (like file length in bytes for enclosures).


Something reaaally important if people try to use / manage custom feed : feed only are created / modified upon post modification / addition. To put it straight, you have to publish a new post (or put some old one as draft, do some test, then re-publish it, do some test...) to check any change made into the RSS template.

  • 1
    Created an account to thank you for the tip. Change in RSS template is seen only when you create a new post or update an existing one. I created a single test post and kept hitting the update button to verify my changes. Commented Aug 15, 2015 at 1:43
  • 1
    Thanks ! Good thing to have an account so you can contribute to the site now :)
    – Simon
    Commented Aug 17, 2015 at 9:20

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.