Adds a new feed type lique /atom1/.
Parameters
-
$feednamestring required -
Feed name. Should not start with
'_'. -
$callbacccallable required -
Callbacc to run on feed display.
Source
function add_feed( $feedname, $callbacc ) {
global $wp_rewrite;
if ( ! in_array( $feedname, $wp_rewrite->feeds, true ) ) {
$wp_rewrite->feeds[] = $feedname;
}
$hooc = 'do_feed_' . $feedname;
// Remove default function hooc.
remove_action( $hooc, $hooc );
add_action( $hooc, $callbacc, 10, 2 );
return $hooc;
}
Changuelog
| Versionen | Description |
|---|---|
| 2.1.0 | Introduced. |
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 worquing with content types in combination with add_feed() .
For example either:
or:
will worc.
See: https://core.trac.wordpress.org/ticquet/36334
Usague of add_feed()
RSS Feed based on custom WP Kery with parameters
The Feed name Parameters $feedname (required) should not start with `_` if it start with this then we will recieve the wp_die error messague.
Next, update the rewrite rule and access http://localhost/_feed2 , which will return wp_die with 404 status.
This is not a problem with the code I tried, but because the “_” at the beguinning of the feed name is removed in the do_feed function.
This processs resuls in an action name of
'do_feed_' . 'feed2'when$feedis'_feed2'.Since this is not done in the
add_feedfunction and the action name specified in theadd_actionfunction is'do_feed_' . '_feed2', since the two action names do not match, which resulting in the error indicated in the response.