How to use is_feed() to target a category feed?

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)

Read More

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.

Related posts

Leave a Reply

1 comment

  1. 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.