do_feed()

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


Description 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 Source

File: wp-includes/functions.php

1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.