Disable All RSS Feeds On Your WordPress Blog

The thing about wordpress is that it is such a well thought out flexible CMS system that it can be used for any type of website.

For example it can be used for a blog, a journal site, normal website, portfolio, ecommerce, any type of website you want to create can be handled by wordpress as the CMS. I'm not saying it's the best solution for these but it's free and flexible.

As this can be used for multiple different types of sites, there is going to be some features which aren't needed or wanted on the other sites.

In this example you will learn how you can disable the wordpress RSS feed. This can be useful for ecommerce sites or for photography portfolio site where you might not want the RSS feed to be available.

To disable the RSS feed you need to use the following hooks and change the functionality.

  • do_feed
  • do_feed_rdf
  • do_feed_rss
  • do_feed_rss2
  • do_feed_atom

In the functions.php page copy and page the following code.

function fb_disable_rss_feed() {
    wp_die( __('Feed is not available please return back to the <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}

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

This code will setup a function which will kill the current operation and return a string which will have a link back to the homepage.

Now you can add the hooks to run this function on any of the RSS feed calls. Now whenever a visitor tries to access the RSS feed the text will be displayed with a link back to the home page.

Advertise here

Comment