Hack: Disable RSS Feeds

There are a few reasons you may want to disable RSS feeds for your WordPress site. You may just not like people reading your content in a feed reader instead of at your site. Or, you may be only displaying certain categories or tags while other content is hidden, and RSS kinda wrecks that.

If, for any reason, you want to disable all RSS feeds, you can do it by adding a function to functions.php or your custom plugin. This function is then hooked into several actions, each of which accounts for a different feed type. You’ll find this code, more or less, all over the place:

function wpaction_disable_rss() {
    wp_die('No feed available.');

add_action('do_feed', 'wpaction_disable_rss', 1);
add_action('do_feed_rdf', 'wpaction_disable_rss', 1);
add_action('do_feed_rss', 'wpaction_disable_rss', 1);
add_action('do_feed_rss2', 'wpaction_disable_rss', 1);
add_action('do_feed_atom', 'wpaction_disable_rss', 1);
add_action('do_feed_rss2_comments', 'wpaction_disable_rss', 1);
add_action('do_feed_atom_comments', 'wpaction_disable_rss', 1);

But here’s what I don’t like about this. This gives an error message when someone tries to access a feed. But it still puts links to these feeds in the header. That’s not right. Browsers and feed readers are still telling people that there is a feed for the site, but when they try to go to the feed they get an error message. So better also remove the feed links in the header.

remove_action( 'wp_head', 'feed_links_extra', 3);
remove_action( 'wp_head', 'feed_links', 2);

Leave a Reply

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