On this page
do_feed()
Loads 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.
Source
File: wp-includes/functions.php. View all references
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 );
}
Hooks
- do_action( "do_feed_{$feed}",
bool $is_comment_feed ,string $feed ) -
Fires once the given feed is loaded.
Related
Uses
| Uses | Description |
|---|---|
| get_query_var() wp-includes/query.php | Retrieves the value of a query variable in the WP_Query class. |
| has_action() wp-includes/plugin.php | Checks if any action has been registered for a hook. |
| get_default_feed() wp-includes/feed.php | Retrieves the default feed. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/do_feed