Disable Feeds on WordPress or bbPress

There comes a time when a man just wants to disable his blog’s feed and then remove those feed links from his site’s <head>. Maybe he’s concluded that said feed has no use for him. Or maybe he’s just tired of making it easier for evildoers to scrape his site’s content.

If you already have some sort of post subscription plugin — where a reader can subscribe to your new posts via email — then you wouldn’t really have any use for feeds. Don’t you just hate it when so-called feed aggregators like “feedreader.com” has scraped posts that rank higher than the original posts? Feedreader has a Google PageRank of 9 which means their framed copy of your article will likely get indexed much sooner than the original.

Disable Feeds for WordPress and bbPress

Adding the following code on your functions.php file will disable RSS, RFD and Atom feeds. This will halt execution of WordPress when a link to a feed is accessed. It also outputs a certain friendly message which you can modify, maybe add links to your homepage. The last line on the code disables feed for bbPress forums, topics and replies. You can remove that if you don’t use bbPress or would not want to remove its feed.

function ra_disable_feed() {
	wp_die( 'The feed has gone away. No word on it\'s return.' );
}
add_action( 'do_feed', 'ra_disable_feed', 1 );
add_action( 'do_feed_rdf', 'ra_disable_feed', 1 );
add_action( 'do_feed_rss', 'ra_disable_feed', 1 );
add_action( 'do_feed_rss2', 'ra_disable_feed', 1 );
add_action( 'do_feed_atom', 'ra_disable_feed', 1 );
add_action( 'do_feed_rss2_comments', 'ra_disable_feed', 1 );
add_action( 'do_feed_atom_comments', 'ra_disable_feed', 1 );
add_action( 'bbp_feed', 'ra_disable_feed', 1 );

The function wp_die() might be too harsh for some. It could cause a bunch of status 500 crawl errors that might show up on your Google Webmasters Tools page. Alternatively, you could replace wp_die() with wp_redirect() which instead of showing an error will just redirect humans, bots and spiders to a url that you specify.

Replace this line:

   wp_die( 'The feed has gone away. No word on it\'s return.' );

With this:

   wp_redirect( 'http://ronangelo.com', 301 ); exit;

Remove Feed Links from <Head>

After disabling the feeds there would still be links pointing to them that are found on the head part of a WordPress page. You can add this other code on your functions.php in addition to the one above.

On themes that are compliant with latest WordPress standards, “automatic-feed-links” functionality is added on the “after_setup_theme” action hook. You’d have to remove it after it has been added so a priority of 99 or higher is ideal. After this, the feed links to post comments will still be available. Those are removed by using “remove_action” to take out the “feed_links_extra” from “wp_head” action hook.

function ra_remove_feed_links() {
	remove_theme_support( 'automatic-feed-links' );
	remove_action( 'wp_head', 'feed_links_extra', 3 );
}
add_action( 'after_setup_theme', 'ra_remove_feed_links', 99 );

Remember to clear your cache if you have a caching plugin installed.

Share This Post

Leave a Reply

Please write your comments in english. I delete anything that even remotely resembles spam.

Note: When posting code, enclose it in pre and code tags.
e.g. <pre><code> Add code here </code></pre>