How to disable RSS feeds in WordPress?

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.

  1. Simplest & Quickest way is Use a plugin
  2. If you’re a advance user and having knowledge of Programming Use WordPress hooks
  3. .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:

###########################################################
# 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 );

/**
 * 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
<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

Post a comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!