The do_feed_{$feed} WordPress PHP action fires once a specific 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
Usage
add_action('do_feed_{$feed}', 'your_custom_function', 10, 2);
function your_custom_function($is_comment_feed, $feed) {
// your custom code here
}
Parameters
$is_comment_feed(bool) – Whether the feed is a comment feed.$feed(string) – The feed name.
More information
See WordPress Developer Resources: do_feed_{$feed}
Examples
Modify RSS feed content
Modify the content of RSS feed items.
add_action('do_feed_rss2', 'modify_rss_feed_content', 10, 2);
function modify_rss_feed_content($is_comment_feed, $feed) {
if (!$is_comment_feed) {
// Change the content of RSS feed items
}
}
Add a custom feed type
Create a custom feed type named ‘json’.
add_action('do_feed_json', 'generate_json_feed', 10, 2);
function generate_json_feed($is_comment_feed, $feed) {
// Generate the JSON feed
}
Disable comment feeds
Disable all comment feeds.
add_action('do_feed_{$feed}', 'disable_comment_feeds', 10, 2);
function disable_comment_feeds($is_comment_feed, $feed) {
if ($is_comment_feed) {
wp_die(__('Comment feeds are not available.'));
}
}
Add custom data to Atom feed
Add custom data to Atom feed items.
add_action('do_feed_atom', 'add_custom_data_to_atom_feed', 10, 2);
function add_custom_data_to_atom_feed($is_comment_feed, $feed) {
if (!$is_comment_feed) {
// Add custom data to Atom feed items
}
}
Limit the number of posts in RSS2 feed
Limit the number of posts in RSS2 feed to 5.
add_action('do_feed_rss2', 'limit_rss2_feed_posts', 10, 2);
function limit_rss2_feed_posts($is_comment_feed, $feed) {
if (!$is_comment_feed) {
// Change the number of posts in RSS2 feed to 5
query_posts('posts_per_page=5');
}
}