You want to disable RSS feed in WordPress, and you don’t know how to do that?
Here are 3 easy ways to do it.
- Simplest & Quickest way is Use a plugin
- If you’re a advance user and having knowledge of Programming Use WordPress hooks
- .htaccess rule to prevent access of the feeds
Let’s review all this steps in detail one-by-one
Simplest & Quickest way is use a plugin
Installing a plugin that will take care of disabling feeds is probably the easiest way to proceed, 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 of WordPress Hooks
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 active child theme:
Ready To Start A Conversation?
We’d love to hear about your next project and how we can help.
GIVE US A CALL
###########################################################
# 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 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 );
/**
* Redirect to the homepage all users trying to access feeds.
*/
function disable_feeds() {
wp_redirect( home_url() );
die;
}
The above code snippet will disable all types of feed (RSS, RDF, Atom) for all types of content (blog posts, comments, custom post types, etc.) and redirect to user on the homepage when 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.
Use .htaccess rule
If your WordPress website is hosted on the Apache server you’ll able to disable the access of RSS feed by adding below code snippet in the begining of your .htaccess file from your root directory
# BEGIN Feed redirect
RewriteEngine on
RewriteRule ^(.*/)?feed(/rss|/rss2|/atom|/rdf)?/?$ /$1 [R=301,NC,L]
RewriteCond %{QUERY_STRING} (?|&)feed=
RewriteRule (.*) $1/? [R=301,NC,L]
# END Feed redirect
Require a solution to your software problems?
Want to get in touch?
Have an idea?
6 responses to “How to disable RSS feeds in WordPress?”
I must thank you for the efforts you have put in penning this website. I really hope to see the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has motivated me to get my own, personal site now 😉
Your grasp of this subject is exceptional.
You’ve earned a dedicated follower in me from here on out.
My web blog e-transfer payday loans canada
Fantastic info With thanks!
Aw, this was an incredibly good post. Finding the time and actual effort to generate a very good article… but what can I say… I hesitate a lot and don’t seem to get nearly anything done.
My brother suggested I might like this blog. He was entirely right.
This post actually made my day. You can not imagine
just how much time I had spent for this info!
Thanks!
Hi, I do think this is an excellent blog. I stumbledupon it 😉 I will return once again since I book
marked it. Money and freedom is the greatest way to change, may you be rich and
continue to help others.