The default_feed WordPress PHP filter allows you to modify the default feed type for your website. Possible values include ‘rss2’ and ‘atom’.
Usage
add_filter('default_feed', 'my_custom_default_feed');
function my_custom_default_feed($feed_type) {
// your custom code here
return $feed_type;
}
Parameters
- $feed_type (string): The type of default feed. Possible values include ‘rss2’ and ‘atom’. Default is ‘rss2’.
More information
See WordPress Developer Resources: default_feed
Examples
Change the default feed type to ‘atom’
To change the default feed type to ‘atom’:
add_filter('default_feed', 'change_default_feed_to_atom');
function change_default_feed_to_atom($feed_type) {
$feed_type = 'atom';
return $feed_type;
}
Set default feed type based on user role
To set the default feed type based on the user role:
add_filter('default_feed', 'set_default_feed_based_on_user_role');
function set_default_feed_based_on_user_role($feed_type) {
if (current_user_can('administrator')) {
$feed_type = 'atom';
} else {
$feed_type = 'rss2';
}
return $feed_type;
}
Modify default feed type using a custom function
To modify the default feed type using a custom function:
add_filter('default_feed', 'modify_default_feed_with_custom_function');
function modify_default_feed_with_custom_function($feed_type) {
$feed_type = my_custom_function();
return $feed_type;
}
function my_custom_function() {
// your custom code here to determine the feed type
return 'rss2';
}
Change default feed type based on query variables
To change the default feed type based on query variables:
add_filter('default_feed', 'change_default_feed_based_on_query_vars');
function change_default_feed_based_on_query_vars($feed_type) {
global $wp_query;
if (isset($wp_query->query_vars['custom_var'])) {
$feed_type = 'atom';
}
return $feed_type;
}
Change default feed type using a plugin option
To change the default feed type using a plugin option:
add_filter('default_feed', 'change_default_feed_using_plugin_option');
function change_default_feed_using_plugin_option($feed_type) {
$plugin_option = get_option('my_plugin_option');
if ($plugin_option === 'atom') {
$feed_type = 'atom';
}
return $feed_type;
}