I want to disable rss feed,my wordpress version is 5.2.4.
see my code below to disable rss feed.
function itsme_disable_feed() {
wp_die( __( 'No feed available' ) );
}
add_action('do_feed', 'itsme_disable_feed', 1);
add_action('do_feed_rdf', 'itsme_disable_feed', 1);
add_action('do_feed_rss', 'itsme_disable_feed', 1);
add_action('do_feed_rss2', 'itsme_disable_feed', 1);
add_action('do_feed_atom', 'itsme_disable_feed', 1);
add_action('do_feed_rss2_comments', 'itsme_disable_feed', 1);
add_action('do_feed_atom_comments', 'itsme_disable_feed', 1);
By the book,the feed page will show wp_die page.But it didn`t show it Expectantly.
It shows this,see the screenshot,and I don`t know how to solve it.
I want to disable rss feed,my wordpress version is 5.2.4.
see my code below to disable rss feed.
function itsme_disable_feed() {
wp_die( __( 'No feed available' ) );
}
add_action('do_feed', 'itsme_disable_feed', 1);
add_action('do_feed_rdf', 'itsme_disable_feed', 1);
add_action('do_feed_rss', 'itsme_disable_feed', 1);
add_action('do_feed_rss2', 'itsme_disable_feed', 1);
add_action('do_feed_atom', 'itsme_disable_feed', 1);
add_action('do_feed_rss2_comments', 'itsme_disable_feed', 1);
add_action('do_feed_atom_comments', 'itsme_disable_feed', 1);
By the book,the feed page will show wp_die page.But it didn`t show it Expectantly.
It shows this,see the screenshot,and I don`t know how to solve it.
Share Improve this question asked Dec 2, 2019 at 19:20 cindycindy 1059 bronze badges 3- Have you flushed rewrite rules and cleared any layers of caching? – WebElaine Commented Dec 2, 2019 at 19:53
- yeah,I have flushed the permalink and cleared the browser cach – cindy Commented Dec 2, 2019 at 19:58
- @Cindy Lu Hope this referrence helpful for you wpcaptain/blog/… – Gopala krishnan Commented Dec 3, 2019 at 10:16
2 Answers
Reset to default 2You need to define the HTTP Response code in wp_die
function.
wp_die( __('No feed available'), '', 404 );
Also set custom header to get HTML page instead of xml page. So the code should be like below.
function itsme_disable_feed() {
global $wp_query;
$wp_query->is_feed = false;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
wp_die( __('No feed available'), '', 404 );
}
have you tried using remove_action?
Example:
<?php
add_action('wp_head', 'remove_feeds_in_head', 1);
function remove_feeds_in_head() {
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
}
EDIT: So disabling them doesn't remove them, to completely get rid of them, them you need to use remove_action aswell. Assuming this is what you want to do.
add_action('do_feed', 'itsme_disable_feed', 1);
add_action('do_feed_rdf', 'itsme_disable_feed', 1);
add_action('do_feed_rss', 'itsme_disable_feed', 1);
add_action('do_feed_rss2', 'itsme_disable_feed', 1);
add_action('do_feed_atom', 'itsme_disable_feed', 1);
add_action('do_feed_rss2_comments', 'itsme_disable_feed', 1);
add_action('do_feed_atom_comments', 'itsme_disable_feed', 1);
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'rsd_link');
// Add whatever other things you want to remove