Disable RSS feeds in WordPress without a plugin
Switch off every RSS and Atom feed with one Snipfire snippet. The Disable Feeds plugin has a couple of options the snippet doesn't; here they are.
What Disable Feeds does
Disable Feeds turns off all RSS, Atom and RDF feeds and sends feed requests to the matching page on your site. The plugin on WordPress.org
What the snippet does the same
- Every feed address, including comment and category feeds, stops returning a feed.
- Feed links leave the page head.
What's different
- The snippet sends every feed request to your home page. The plugin sends it to the matching page instead, so a category feed goes to that category.
- The plugin can show a 404 page instead of redirecting, and can keep the main post and comment feeds. Its options are under Settings > Reading. The snippet has no options.
When to keep the plugin Keep the plugin if you want feed requests to land on the matching page or to keep your main feed.
The snippet: Turn off RSS feeds
Every feed address (/feed/, comment feeds, category feeds) sends visitors to the home page, and the feed links leave the page head.
<?php
$no_feed = static function () {
wp_safe_redirect( home_url( '/' ), 301 );
exit;
};
foreach ( array( 'do_feed', 'do_feed_rdf', 'do_feed_rss', 'do_feed_rss2', 'do_feed_atom', 'do_feed_rss2_comments', 'do_feed_atom_comments' ) as $feed ) {
add_action( $feed, $no_feed, 1 );
}
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
Notes, where it runs and what it was tested with
Switching from the plugin
- Install the snippet in Snipfire (it arrives switched off).
- Deactivate Disable Feeds.
- Switch the snippet on. Snipfire checks the code and test-loads your site first.
- Check the page it affects, then delete the plugin.