WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using add_feed() to create some custom feeds but calls to is_singular(), is_home() etc... just don't seem to work within the callback. Is there a workaround for this?

Example code:

add_action( 'init', 'my_init' );
function my_init() {    
    add_feed( 'new_feed', 'feed_output' );

function feed_output() {
    if ( is_home() )
        load_template( '/path/to/feed/home/template.php' );
        load_template( '/path/to/feed/template.php' );

I've added a trac ticket for this too.

share|improve this question
up vote 1 down vote accepted

You can only use conditional tags after the posts_selection action hook has run.

According to the codex article on add_feed it should be called with the init action, which runs before. Now I don't know when and how you run it, because you don't say so in the above example, but I'd assume you do it before posts_selection - that would explain your dilemma anyway.

share|improve this answer
Thanks, I've added the context - I am actually calling it on init as the codex suggests. wp_head would be way too late as the output from the theme would already be rendering. Didn't seem to work on the wp action either... – sanchothefat Sep 28 '12 at 18:37
Well tough luck, I guess. Then, as far as I see it, it just is impossible to use add/remove feeds based on conditional tags. Since wp_head is too late and wp doesn't cut it either, I removed my suggested yet untested way of handling things. The rest of the answer should still apply, I suppose. – Johannes Pille Sep 28 '12 at 18:54
Yeah, had a reply on the trac ticket. Apparently it doesn't make sense to return true for is_home etc... on a feed even though the feed changes with context... – sanchothefat Oct 1 '12 at 11:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.