do_feed

The timeline below displays how wordpress function do_feed has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Loads the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query WordPress Query object.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ('' === $feed || 'feed' === $feed) {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('<strong>Error:</strong> This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     *
     * Possible hook names include:
     *
     *  - `do_feed_atom`
     *  - `do_feed_rdf`
     *  - `do_feed_rss`
     *  - `do_feed_rss2`
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 5.8

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query WordPress Query object.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ('' === $feed || 'feed' === $feed) {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('Error: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     *
     * Possible hook names include:
     *
     *  - `do_feed_atom`
     *  - `do_feed_rdf`
     *  - `do_feed_rss`
     *  - `do_feed_rss2`
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 5.5

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query WordPress Query object.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ('' === $feed || 'feed' === $feed) {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('Error: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 5.4

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query WordPress Query object.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ('' == $feed || 'feed' === $feed) {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('Error: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 5.3

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query WordPress Query object.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 7.3

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query Used to tell if the use a comment feed.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 4.7

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query Used to tell if the use a comment feed.
 */
function do_feed()
{
    global $wp_query;
    // Determine if we are looking at the main comment feed
    $is_main_comments_feed = $wp_query->is_comment_feed() && !$wp_query->is_singular();
    /*
     * Check the queried object for the existence of posts if it is not a feed for an archive,
     * search result, or main comments. By checking for the absense of posts we can prevent rendering the feed
     * templates at invalid endpoints. e.g.) /wp-content/plugins/feed/
     */
    if (!$wp_query->have_posts() && !($wp_query->is_archive() || $wp_query->is_search() || $is_main_comments_feed)) {
        wp_die(__('ERROR: This is not a valid feed.'), '', array('response' => 404));
    }
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 4.4

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query Used to tell if the use a comment feed.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    if (!has_action("do_feed_{$feed}")) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic portion of the hook name, `$feed`, refers to the feed template name.
     * Possible values include: 'rdf', 'rss', 'rss2', and 'atom'.
     *
     * @since 2.1.0
     * @since 4.4.0 The `$feed` parameter was added.
     *
     * @param bool   $is_comment_feed Whether the feed is a comment feed.
     * @param string $feed            The feed name.
     */
    do_action("do_feed_{$feed}", $wp_query->is_comment_feed, $feed);
}

WordPress Version: 4.3

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query Used to tell if the use a comment feed.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    $hook = 'do_feed_' . $feed;
    if (!has_action($hook)) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic hook name, $hook, refers to the feed name.
     *
     * @since 2.1.0
     *
     * @param bool $is_comment_feed Whether the feed is a comment feed.
     */
    do_action($hook, $wp_query->is_comment_feed);
}

WordPress Version: 4.0

/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @uses $wp_query Used to tell if the use a comment feed.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    $hook = 'do_feed_' . $feed;
    if (!has_action($hook)) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic hook name, $hook, refers to the feed name.
     *
     * @since 2.1.0
     *
     * @param bool $is_comment_feed Whether the feed is a comment feed.
     */
    do_action($hook, $wp_query->is_comment_feed);
}

WordPress Version: 3.9

/**
 * Loads the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @uses $wp_query Used to tell if the use a comment feed.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    $hook = 'do_feed_' . $feed;
    if (!has_action($hook)) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    /**
     * Fires once the given feed is loaded.
     *
     * The dynamic hook name, $hook, refers to the feed name.
     *
     * @since 2.1.0
     *
     * @param bool $is_comment_feed Whether the feed is a comment feed.
     */
    do_action($hook, $wp_query->is_comment_feed);
}

WordPress Version: 3.7

/**
 * Loads the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 * @uses $wp_query Used to tell if the use a comment feed.
 * @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed.
 */
function do_feed()
{
    global $wp_query;
    $feed = get_query_var('feed');
    // Remove the pad, if present.
    $feed = preg_replace('/^_+/', '', $feed);
    if ($feed == '' || $feed == 'feed') {
        $feed = get_default_feed();
    }
    $hook = 'do_feed_' . $feed;
    if (!has_action($hook)) {
        wp_die(__('ERROR: This is not a valid feed template.'), '', array('response' => 404));
    }
    do_action($hook, $wp_query->is_comment_feed);
}