Even though they are still used regularly by many people, nowadays RSS feeds are not as popular as they were a decade ago. And there are plenty of valid reasons why you might want to disable them on your WordPress website.
3 ways to disable RSS and Atom feeds for WordPress websites
Use a plugin
Installing a plugin that will take care of disabling feeds is probably the easiest way to proceed, above all if you’re not comfortable with playing with the code.
There are a couple of plugins that can allow you to disable feeds, but most of them come with other features you might not need. However, the Disable Feeds plugin can take care of disabling RSS feeds without bloating your WordPress install with other unwanted features.
Use WordPress hooks and add the following lines to your functions.php file
This is personally what I recommend. In most cases, a plugin isn’t needed in order to disable feeds, since feeds can be disabled with only a couple of lines of code.
In order to disable feeds, you can simply add the following lines at the end of the functions.php
file of your current theme:
/**
* Redirect to the homepage all users trying to access feeds.
*/
function disable_feeds() {
wp_redirect( home_url() );
die;
}
// Disable global RSS, RDF & Atom feeds.
add_action( 'do_feed', 'disable_feeds', -1 );
add_action( 'do_feed_rdf', 'disable_feeds', -1 );
add_action( 'do_feed_rss', 'disable_feeds', -1 );
add_action( 'do_feed_rss2', 'disable_feeds', -1 );
add_action( 'do_feed_atom', 'disable_feeds', -1 );
// Disable comment feeds.
add_action( 'do_feed_rss2_comments', 'disable_feeds', -1 );
add_action( 'do_feed_atom_comments', 'disable_feeds', -1 );
// Prevent feed links from being inserted in the <head> of the page.
add_action( 'feed_links_show_posts_feed', '__return_false', -1 );
add_action( 'feed_links_show_comments_feed', '__return_false', -1 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
This will completely disable all types of feed (RSS, RDF, Atom) for all types of content (blog posts, comments, custom post types, etc.) and redirect to the homepage any user trying to browse the feeds. This will also remove the <link rel="alternate" type="application/rss+xml" href="/feed/" />
tag inserted by default in the <head>
of your page for both comment and post feeds.
Add rules to the .htaccess file to prevent access to the feeds
This is not my favorite option, but it’s still valid and it works, as long as your website is served by Apache. You can add the following rules in your .htaccess
file, before the # BEGIN WordPress
line (if you don’t see that line, then add these rules at the beginning of the file) :
# BEGIN Feed redirect
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*/)?feed(/rss|/rss2|/atom|/rdf)?/?$ /$1 [R=301,NC,L]
RewriteCond %{QUERY_STRING} (?|&)feed=
RewriteRule (.*) $1/? [R=301,NC,L]
</IfModule>
# END Feed redirect
With that piece of code added to your .htaccess
file, it will work whether you have enabled custom permalinks or not, and trying to browse any feed will redirect the user either to the homepage of your site, or to the corresponding post/author/archive page.
If you know another way of disabling RSS feeds in WordPress, feel free to share it with us in the comments!
Hi Dave,
Thanks for your great article!
I need to disable the author’s feed,
I have already disabled author pages (on function.php to 404 page so google will permanently remove these pages from index) but author’s feeds are still running.
So I need to point to 404 pages like /author/name/feed.
Can you help me in some way?
Thanks
Hello how did you disable author pages in function.php ?
Great article
Quick question I want to remove all feeds including author feeds – do I use the top code and bottom code to do this ?
Many thanks for your help
Hi Graham,
Please see my answer in my previous comment here: https://wpcaptain.com/blog/how-to-disable-rss-feeds-completely-in-wordpress/#comment-932
Have a nice day!
Hi there and many thanks for your reply. Is there anyway when disabling all the feeds rather than doing a redirect to my homepage, they are directed to my custom 404.php page – if I can return 404 I can get all the urls removed from Google search console
Many thanks for all your help
Hi Graham,
To trigger a 404 page, you could try the following (untested):
Replaces:
wp_redirect( home_url() );
die;
With:
global $wp_query;
$wp_query->set_404();
status_header( 404 );
require get_404_template();
die();
So the final function looks like this:
Does it help?
Hi Frank,
If you only want to disable feeds for authors, you could use the following:
Hope it helps!
Awesome! it is working perfectly fine. Thanks for this great tutorial.
Hi, Many thanks for your quick reply – I want to disable all wordpress feeds and return my 404.php page – not just the author feeds
Many thanks for all your help
I’ve modified the redirect to go to the post itself, seems better to me, no?
function disable_feeds() {
global $post;
wp_redirect( get_permalink( $post->post_parent ), 301 );
exit;
}
It could be, but why are you using the post_parent instead of the actual post ID ?