[wp-trac] [WordPress Trac] #22031: Conditional tags don't work within add_feed() callback function

WordPress Trac wp-trac at lists.automattic.com
Fri Sep 28 10:50:28 UTC 2012


#22031: Conditional tags don't work within add_feed() callback function
-----------------------------+-------------------------
 Reporter:  sanchothefat     |       Type:  enhancement
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Feeds
  Version:                   |   Severity:  normal
 Keywords:  dev-feedback     |
-----------------------------+-------------------------
 I was putting together a custom feed and wanted to pick a different
 template based on the context of where I was in the site. So for example I
 wanted one feed template on the home/front page and another for category
 pages.

 Using `add_feed()` and browsing to that feed results in only `is_feed()`
 being true and not any of the other conditional tags.

 I was wondering if a) there's a reason for that and b) if it's something
 we could fix.

 I'm not entirely sure where to look though. Attempts at running
 `$wp_query->parse_query_vars()` to force the conditionals to be set were
 unsuccessful.

 The following code is a quick demo:

 {{{
 add_feed( 'new_feed', 'feed_output' );

 function feed_output() {
     if ( is_home() )
         echo 'home feed';
     if ( is_singular() )
         echo 'singular feed';
     if ( is_category() )
         echo 'category feed';
 }
 }}}

 Nothing will be output on /feed/new_feed/ URLs even if on home, single or
 category page.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22031>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list