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.
2 Answers
You 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 );
}