Become Wordpress Professional - Your Ultimate Wordpress Guide

Friday, 26 July 2013

How to Disable RSS Feeds in Wordpress

Sometimes it is required for a wordpress site owner to disable RSS feeds because of the fear that someone might fetch their latest posts by some script or because a simple static site is the requirement.

This tutorial will help you disable RSS feeds of your wordpress site for as long as one likes.

First of all log into your wordpress admin panel.

Navigate to Appearance > Editor then open up your theme's functions.php file.

Next copy this simple code below and paste it at the bottom of your functions.php file and save the changes:
function fb_disable_feed() {
function fb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="get_bloginfo('url')">homepage</a>!') );
}

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);

The above code uses action hooks to disable the RSS feeds of the wordpress site. We have defined a function named fb_disable_feed() and used a couple of pre-defined wordpress action hooks to disable the default RSS and atom feeds. The first argument of the add_action function is the pre-defined wordpress hook and the second argument is the function name that we to be executed.

You can get to know about the complete list of wordpress Hooks available here

If later on you want to re-enable the RSS/atom feeds of your wordpress blog, simply remove the chunk of code that you inserted and feeds will start working as normal.

0 comments:

Post a Comment

Please Avoid Spamming. Comments will be moderated before they are published.