How to secure or disable the RSS feeds?

I’m trying to set up WordPress as a CMS. As such, I want to disable the feeds since it’s mostly a secured site. I’ve gone through all the Settings pages but found no setting to tweak or disable the feeds. So I guess I need to write a custom function or plugin to do this. But how?

Concerning what feeds exist, I knew of at least these links…

http://example.com/comments/feed/
http://example.com/feed/

So, in addition to the main question, I’m also slightly worried: does the above code catch all feeds that are available? And is this really the way to disable all feeds?

I know that plugin support is off-topic here. However, just for some context / as a footnote, I’m using the following combination of relevant moving parts:

  • WordPress 4
  • GeneratePress theme
  • Groups plugin

I’ve managed to secure access to pages and blog posts using the plugin. However, when unauthenticated users visit a feed URL it still shows content. Because the plugin can’t seem to do what I want I decided to write some code myself to do this.

(I’ve gone through the Appearance > GeneratePress page but nothing is activated. I’ve also gone through the Appearance > Customize page (and all settings), but found nothing there either. Finally, I’ve re-read the “Groups” plugin’s Options several times over but found no option.)

2 s
2

As pointed out in the comments by @kaiser, your question is very similar to this question. In fact, the question itself holds the answer. To disable all feeds add the following code…

function itsme_disable_feed() {
    wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( "https://wordpress.stackexchange.com/" ) ) .'">homepage</a>!' ) );
}

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

…to an empty plugin, and activate that plugin. This should prevent anyone from accessing a feed action.

Note that the above is sample code only, preferably you’d not wp_die but redirect or use a 404 instead.

Leave a Comment