WordPress is known to people as a robust and reliable blogging system. People use RSS Feeds to subscribe to new content you publish through third-party applications like Feedly, for example.
However, not everyone uses WordPress for a blog, and there are many businesses that have a WordPress site for a single page or any representative site for the business. In this case, you might want to completely disable the
Feed options and have one less thing to worry about.
By default, WordPress generates several types of feeds, such as:
https://example.com/feed/
https://example.com/feed/rss/
https://example.com/feed/rss2/
https://example.com/feed/rdf/
https://example.com/feed/atom/
It also generates these for your categories, tags, and comments. And speaking of comments, if you don’t have a blog, you might also want to completely disable
comments in WordPress as well.
But for our purposes, let’s see how to disable those feeds in WordPress. You can probably do this with a plugin like this or
another, but in our case, let’s see how to do it with code.
Disabling RSS Feeds in WordPress Using Code
Copy the following code to your functions.php
file in your theme, or more correctly, in your child theme:
function sv_disable_feed() {
wp_die(__('No feed available, please visit the <a href="' . esc_url(home_url('/')) . '">homepage</a>!'));
}
add_action('do_feed', 'sv_disable_feed', 1);
add_action('do_feed_rdf', 'sv_disable_feed', 1);
add_action('do_feed_rss', 'sv_disable_feed', 1);
add_action('do_feed_rss2', 'sv_disable_feed', 1);
add_action('do_feed_atom', 'sv_disable_feed', 1);
add_action('do_feed_rss2_comments', 'sv_disable_feed', 1);
add_action('do_feed_atom_comments', 'sv_disable_feed', 1);
Now, if someone tries to access the feed address on your site (domain.co.il/feed), they will receive the following message:
As seen in the image below, WordPress also generates links to those feeds in the header of your site pages. If you have disabled the feed on your site or if it is not relevant, you may want to remove these links from the HTML
code that your site generates.
Copy the following code to your functions.php
file to remove those feed links located in the header of the site:
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
That’s it… Good luck!