Disable WordPress RSS  Feeds

How to disable all built-in RSS feeds in WordPress.

There are other methods to do this, but I’ve found this approach to be the most efficient. Instead of

Removing feed rewrite rules is an effective way to disable all RSS feeds in a WordPress website. It’s also very efficient, it reduces the total number of rewrites that PHP checks for by about 50%. I use this myself when it’s necessary to remove RSS feeds from a WordPress website. It’s the best approach in my opinion.

/**
 * Disable All RSS Feeds
 */
add_action( 'rewrite_rules_array', function ( $rules ) {
  foreach ( $rules as $rule => $rewrite ) {
    if ( strstr( $rule, '(atom|rdf|rss|rss2|feed|commentsrss2)' ) ) {
      unset( $rules[$rule] );
    }
  }

  return $rules;
} );

After adding this function to your website’s theme or plugin, all feed related URL’s will return your theme’s 404 / Page Not Found template. The one downside to this approach is that you’ll need to flush your site’s permalinks. It’s easy to do, just visit the Settings > Permalinks page in your WordPress admin area. When this page is visited, WordPress will automatically flush/refresh all URL rewrites.

Method #2: Intercepting Feeds with do_feed Hooks

WordPress provides do_feed and do_feed_* hooks for filtering RSS and other XML feeds. These can be used to intercept feeds and disable them before they’re processed. Many of the examples around the web use the wp_die function to halt/deactivate feeds, but this isn’t ideal because it returns a 500 Internal Server Error. It’s bad for SEO and not ideal in other ways as well, I prefer serving up a 404 Page Not Found response instead which seems more appropriate.

/**
 * Intercept & Disable RSS/XML Feeds
 */
function kevinlearynet_disable_feeds() {
  global $wp_query;
  $wp_query->is_404 = true;
  status_header( 404 );
  nocache_headers();
  include get_query_template( '404' );
  exit;
}
add_action( 'do_feed', 'wp_disable_feeds', 1 );
add_action( 'do_feed_rdf', 'wp_disable_feeds', 1 );
add_action( 'do_feed_rss', 'wp_disable_feeds', 1 );
add_action( 'do_feed_rss2', 'wp_disable_feeds', 1 );
add_action( 'do_feed_atom', 'wp_disable_feeds', 1 );
add_action( 'do_feed_rss2_comments', 'wp_disable_feeds', 1 );
add_action( 'do_feed_atom_comments', 'wp_disable_feeds', 1 );

This has the same effect as the previous method, returning your theme’s 404 Page Not Found template when a feed URL is visited. I prefer the first method because it reduces rewrite rules and make the site more efficient. Why check the URL for RegExp rewrite patterns when we’re just going to serve a 404? If you’re more comfortable with this approach, though, I understand. The one benefit is that you don’t need to flush your site’s permalinks to get it working.

Related Articles

Meet the Author

Kevin Leary, WordPress Consultant

I'm a custom WordPress web developer and analytics consultant in Boston, MA with 16 years of experience building websites and applications. View a portfolio of my work or request an estimate for your next project.