Completely disable RSS feeds on WP 5.5.2 and show a 404 page instead of die();

Question

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.com/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.com/feed/

no corresponding rules are set in .htaccess file
Thanks in advance.

0
api2_go 3 months 0 Answers 13 views 0

Leave an answer