Last updated December 6th, 2023 05:49
Perhaps you have also wondered how to disable RSS feed in WordPress with the code, as you may not want to use a plugin for everything. Or maybe you’re just wondering if disabling RSS feed makes any sense.
The WordPress functionality called RSS feed is mainly used on websites that regularly add new content at certain intervals. We are talking mainly about blogs, where you upload new content with a certain regularity. RSS feed has one purpose. To make it easier for users to find new content on their favorite websites. Let me give you an example.
What is the RSS feed?
If you actively follow the content of, say, 10 websites, it is quite time-consuming to check every day if the authors have added new content to their websites. You have to open 10 pages every morning and check if there is a new article. You could might interest in it or not. Using an RSS reader, where you save the RSS feed of each website you follow, will be much more convenient for you. The reader will scan all ten websites for you, and if it finds new content, it will download it and notify you. Since you will see the title and at least part of the content of the article, you can decide if it is interesting for you and whether you want to read the whole article on the website. For small websites, where the author does not change the content, there is no point in using and enabling RSS feed. Let’s look at how to disable RSS feed in WordPress using code for such websites.
You may now be wondering why use code when there is certainly a plugin that would solve the same problem. And you’re right, there is. However, if you always use a plugin for even small problems, you will soon reach a point of crash. Yours WordPress will be slow and overwhelmed. It will simply run out of allocated memory. So it’s good to be able to solve small problems differently. After all, it’s not as difficult as it may seem from the title.
How to disable RSS in WordPress with the code
One plugin, however, you will truly need. It’s a plugin for inserting so-called snippets. SSince many problems in WordPress can be solved with code. So thanks to this plugin, you are able to tackle a wide range of issues. This one plugin can boldly replace even ten other plugins.
The plugin that I personally use for inserting snippets is called WPCode. The direct download link is available here: WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager. Of course, you can install it directly from the administration panel by clicking on the “Plugins” link in the left menu and then on “Add New“. In the search field, type “WPCode” to find and install the plugin. After installation, be sure to activate it as well.
How to Disable RSS Feed in WordPress using WPCode
After installing the WPCode plugin, you will see a new menu item named “Code Snippet” on the left-hand side of your dashboard. Under this menu, there is another item with the same name (as shown in the tutorial gallery below). To add a new snippet, click on “Add New” and then “Add Your Custom Code (New Snippet)“. Select PHP as the language for the code from the dropdown menu.
Copy and paste the code below into the “Code Preview” field. To make sure the code is automatically executed on all devices, select “Auto Insert” in the “Insertion” section. Than choose “Any Device Type” in the “Device Type” section. This will ensure that the code is automatically executed on mobile, tablet, and desktop devices. Finally, save the snippet and activate it if necessary. If you are using a caching plugin, remember to clear the cache!
The code for disabling RSS Feed in WordPress looks like this:”
/**
* Display a custom message instead of the RSS Feeds.
*
* @return void
*/
function wpcode_snippet_disable_feed() {
wp_die(
sprintf(
// Translators: Placeholders for the homepage link.
esc_html__( 'No feed available, please visit our %1$shomepage%2$s!' ),
' ',
''
)
);
}
// Replace all feeds with the message above.
add_action( 'do_feed_rdf', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss2', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_atom', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss2_comments', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_atom_comments', 'wpcode_snippet_disable_feed', 1 );
// Remove links to feed from the header.
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
Conclusion
By inserting the aforementioned code using a snippet, you can disable the RSS feed in WordPress very easily without having to use another plugin for this action. Additionally, if you learn to use snippets to solve smaller issues and troubles with WordPress behavior, it will not only benefit you, but also your users. Your website users will get a lighter and more agile website where no more than 30 plugins are running, which is usually a lot, especially for solving minor problems. Disabling RSS in WordPress using code is not only simple and likable, but also functional. This solution will also save you some memory that another plugin in line would consume for the same action.
The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.
Byl pro Vás tento článek užitečný?
Klikni na počet hvězd pro hlasování.
Průměrné hodnocení. 0 / 5. Počet hlasování: 0
Zatím nehodnoceno! Buďte první
Je mi líto, že pro Vás nebyl článek užitečný.
Jak mohu vylepšit článek?
Řekněte mi, jak jej mohu zlepšit.
Subscribe to the Newsletter
Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.