add_feed( string $feedname, callable $callback ): string
Adds a new feed type like /atom1/.
Parameters
-
$feedname
string Required -
Feed name.
-
$callback
callable Required -
Callback to run on feed display.
Return
string Feed action name.
More Information
Requires one-time use of flush_rules() to take effect.
Source
File: wp-includes/rewrite.php
.
View all references
function add_feed( $feedname, $callback ) {
global $wp_rewrite;
if ( ! in_array( $feedname, $wp_rewrite->feeds, true ) ) {
$wp_rewrite->feeds[] = $feedname;
}
$hook = 'do_feed_' . $feedname;
// Remove default function hook.
remove_action( $hook, $hook );
add_action( $hook, $callback, 10, 2 );
return $hook;
}
Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
When a new custom feed is added, the endpoint will render using a `Content-Type: application/octet-stream; charset=UTF-8` by default. It would be useful to document working with content types in combination with add_feed().
For example either:
or:
will work.
See: https://core.trac.wordpress.org/ticket/36334
Usage of add_feed()
RSS Feed based on custom WP Query with parameters