How To Disable Your RSS Feed

A question I've seen from time to time is how do I disable my RSS feed? The answer is surprisingly easy. But before I get to that you may be wondering why someone would want to do that. There could be any number of reasons such as you're using WordPress as a CMS with basically static content rather than a blog with dynamic content. In this case a feed wouldn't really serve a purpose. Perhaps you're fed up with scrapers and see this as a last resort. The reason is irrelevant.

All we need to do is add a bit of code to the active theme's functions.php file. Before we begin be sure to backup that file. If you make a mistake you may bork your entire site. Open the active theme's functions.php file in a plain text editor and add the following...

//disable feed
function fb_disable_feed() {
	wp_die( __('<strong>Error:</strong> No RSS feed available, please visit our <a href="'. get_bloginfo('url') .'">homepage</a> for the latest articles!') );
}

add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);

Now when you click one of your RSS links you will see the following message, (click image to enlarge)

If you want to reactivate the feed simply delete the code you added to the functions.php file. It goes without saying this is theme-specific. That is, if you change themes you'll have to add the code to that theme's functions.php file as well. Or, you could make a plugin out of this and drop it in your plugin folder. That way it will work regardless of the theme you are using. It's much easier to turn off as well.

Upon re-reading my post it occurred to me some of you may not know how to turn this in to a plugin. Fear not for I have done it for you. You can get Feed Killer from the Downloads page. [currently unavailable] Simply download the ZIP to your computer, extract the file feed_killer.php and upload it to your plugin folder. Activate as you would any other plugin. To turn your feed back on deactivate the plugin. I should have searched the WordPress plugin repo prior to doing this as such a plugin already exists. You can download it there.

Edit: New information has come to my attention as to the original author of the snippet above. Thanks to Alex at WP Engineer.com!

post
About Len Kutchma

Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him writing the occasional article and toiling away in the forums at WeblogToolsCollection.com. He also hangs out at the WordPress support forums lending a hand where he can. Be sure to follow @wpcanada on Twitter.

Please Note: WPCanada is a moderated community. Please read the Comment Policy.

What Do You Think?

*