Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

is_feed (one of the many conditional tags) can be used to determine if the current query is for a feed.

But how do I use it to target all category feeds? (or tag or custom taxonomy feeds for that matter)

This doesn't seem right:

if (is_category()) {

    if (is_feed()) {
        // Code Goes here
    }

}

And I have no clue as to whatelse I'd try.

share|improve this question
    
What are you trying to do here? Wordpress has the ability to create a feed for any and all categories, and you can link to that feed using (for instance): example.com/?cat=42&feed=rss2 (for more information on feeds, see Wordpress Feeds) –  Vivienne Mar 10 '13 at 10:18
    
@Vivienne I'd prefer modifying the feed itself rather than use a different URL for my use-case in which I am making drastic changes to the posts displayed (and loop) for a custom taxonomy. –  its_me Mar 10 '13 at 10:27
    
Ah, so you're trying to customize your RSS feeds. Maybe this will help: Customizing Feeds –  Vivienne Mar 10 '13 at 10:33
    
@Vivienne Thanks for trying to help, but I'd done all that background work before asking the question. –  its_me Mar 10 '13 at 10:48
    
OK, you never know :-). Glad @birgire could help. –  Vivienne Mar 10 '13 at 10:52
add comment

1 Answer 1

up vote 2 down vote accepted

If you want to determine if you are in a category feed, for example:

 http://example.com/category/football/feed

you can do so with

add_action('wp', 'mycheck');
function mycheck() {
    if(is_feed() && is_category() ){
        // do stuff    
    }
}

or

add_action('wp', 'mycheck');
function mycheck() {
    global $wp_query;

    if($wp_query->is_feed && $wp_query->is_category){
        // do stuff
    }

}

You can similarly check if you are in a tag feed, for example:

 http://example.com/tag/liverpool/feed

with is_tag.

You can then check if you are in a custom taxonomy feed, for example:

 http://example.com/country/england/feed

with is_tax.

share|improve this answer
    
Oh, thank you so much. It didn't occur to me that I'd indeed use the && operator –  its_me Mar 10 '13 at 10:39
    
ok great, good luck with your project. –  birgire Mar 10 '13 at 10:42
    
I think the pre_get_posts filter would be more appropriate to set() or get() the $wp_query values. –  kaiser Mar 10 '13 at 14:38
add comment

Your Answer

 
discard

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.