do_feed() WordPress Function

The do_feed() function is one of the most important functions in WordPress. It is responsible for generating the RSS feed for your site. Without it, your visitors would not be able to subscribe to your content. The do_feed() function is relatively simple. It takes two arguments: the first is the name of the feed, and the second is the URL of the feed. It then uses these two arguments to generate the RSS feed. The do_feed() function is called automatically whenever a visitor tries to access your RSS feed. However, you can also call it directly from your code if you need to. That's all there is to the do_feed() function! It's a simple but essential part of WordPress.

do_feed() #

Load the feed template from the use of an action hook.


Description

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.


Top ↑

Source

File: wp-includes/functions.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More