I'd like to completely disable RSS feeds on my WP website. Can someone please guide me on how to throw a 404.php page and set the headers to 404, when someone types in /
here is the code in functions.php:
function disable_feeds() {
global $wp_query;
$wp_query->is_feed = false;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action( 'do_feed', 'disable_feeds', 1 );
add_action( 'do_feed_rdf', 'disable_feeds', 1 );
add_action( 'do_feed_rss', 'disable_feeds', 1 );
add_action( 'do_feed_rss2', 'disable_feeds', 1 );
add_action( 'do_feed_atom', 'disable_feeds', 1 );
add_action( 'do_feed_rss2_comments', 'disable_feeds', 1 );
add_action( 'do_feed_atom_comments', 'disable_feeds', 1 );
add_action( 'feed_links_show_posts_feed', '__return_false', 1 );
add_action( 'feed_links_show_comments_feed', '__return_false', 1 );
Strangely, I get a 500 Internal Server Error when typing /
no corresponding rules are set in .htaccess
file
Thanks in advance.
I'd like to completely disable RSS feeds on my WP website. Can someone please guide me on how to throw a 404.php page and set the headers to 404, when someone types in https://example/feed/
here is the code in functions.php:
function disable_feeds() {
global $wp_query;
$wp_query->is_feed = false;
$wp_query->set_404();
status_header( 404 );
nocache_headers();
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}
add_action( 'do_feed', 'disable_feeds', 1 );
add_action( 'do_feed_rdf', 'disable_feeds', 1 );
add_action( 'do_feed_rss', 'disable_feeds', 1 );
add_action( 'do_feed_rss2', 'disable_feeds', 1 );
add_action( 'do_feed_atom', 'disable_feeds', 1 );
add_action( 'do_feed_rss2_comments', 'disable_feeds', 1 );
add_action( 'do_feed_atom_comments', 'disable_feeds', 1 );
add_action( 'feed_links_show_posts_feed', '__return_false', 1 );
add_action( 'feed_links_show_comments_feed', '__return_false', 1 );
Strangely, I get a 500 Internal Server Error when typing https://example/feed/
no corresponding rules are set in .htaccess
file
Thanks in advance.
2 Answers
Reset to default 3You need to define the HTTP Response code in wp_die
function.
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!'), '', 404 );
If I want to bail out of my WP, I do it like this:
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
I'm actually not sure, why you get a 500 error. I'd try to comment out the lines of your function one-by-one and see, where the error occurs.