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 ?
Code is working :
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_rss2
after 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).
ADDITIONALLY
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.