Using WordPress ‘is_feed()’ PHP function

The is_feed() WordPress PHP function determines whether the query is for a feed.

Usage

is_feed( $feeds );

Example:

Input:

if ( is_feed( 'rss2' ) ) {
    echo 'This is an RSS2 feed.';
}

Output:

This is an RSS2 feed.

Parameters

  • $feeds (string|string[] – Optional) – Feed type or array of feed types to check against. Default: ”

More information

See WordPress Developer Resources: is_feed()

Examples

Check if the query is for any feed

if ( is_feed() ) {
    echo 'This is a feed.';
}

Check if the query is for an RSS2 feed

if ( is_feed( 'rss2' ) ) {
    echo 'This is an RSS2 feed.';
}

Check if the query is for either an Atom or RSS2 feed

if ( is_feed( array( 'atom', 'rss2' ) ) ) {
    echo 'This is either an Atom or an RSS2 feed.';
}

Display different content based on the feed type

if ( is_feed( 'rss2' ) ) {
    echo 'This is an RSS2 feed.';
} elseif ( is_feed( 'atom' ) ) {
    echo 'This is an Atom feed.';
} else {
    echo 'This is not a feed.';
}

Check if the query is NOT for a feed

if ( ! is_feed() ) {
    echo 'This is not a feed.';
}