admin管理员组

文章数量:1203386

There are loads of articles out there on how to completely disable Wordpress RSS feeds, my configuration (functions.php) is:

function disable_feed() {
  wp_die( 'You Died' , 200 );
}
add_action('do_feed', 'disable_feed', 1);
add_action('do_feed_rdf', 'disable_feed', 1);
add_action('do_feed_rss', 'disable_feed', 1);
add_action('do_feed_rss2', 'disable_feed', 1);
add_action('do_feed_atom', 'disable_feed', 1);
add_action('do_feed_rss2_comments', 'disable_feed', 1);
add_action('do_feed_atom_comments', 'disable_feed', 1);

But instead of getting a nice-looking HTML page with the bordered content normally associated with the wp_die() function, when browsing to https://website/feed/ I'm getting this knarley page back:

Anyone know what I'm doing wrong?

David.

There are loads of articles out there on how to completely disable Wordpress RSS feeds, my configuration (functions.php) is:

function disable_feed() {
  wp_die( 'You Died' , 200 );
}
add_action('do_feed', 'disable_feed', 1);
add_action('do_feed_rdf', 'disable_feed', 1);
add_action('do_feed_rss', 'disable_feed', 1);
add_action('do_feed_rss2', 'disable_feed', 1);
add_action('do_feed_atom', 'disable_feed', 1);
add_action('do_feed_rss2_comments', 'disable_feed', 1);
add_action('do_feed_atom_comments', 'disable_feed', 1);

But instead of getting a nice-looking HTML page with the bordered content normally associated with the wp_die() function, when browsing to https://website/feed/ I'm getting this knarley page back:

Anyone know what I'm doing wrong?

David.

Share Improve this question asked Mar 16, 2022 at 21:19 David AdamsDavid Adams 335 bronze badges 1
  • See wordpress.org/support/topic/… – 8ctopus Commented Jun 20, 2023 at 11:58
Add a comment  | 

2 Answers 2

Reset to default 0

Add following code to: functions.php

 function itsme_disable_feed() {
     wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( '/' ) ) .'">homepage</a>!' ) );
    }

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_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );

I just couldn't get this to work. I was expecting the wp_die() function to provide its message on a pretty HTML page, like this example: https://www.wpbeginner.com/wp-tutorials/how-to-disable-rss-feeds-in-wordpress/

...but all I get is this nasty XML tree.

I've changed my solution now to instead HTTP302 redirect the visitor to ./feed/ to the homepage. This is actually a better solution, I believe, because it means Wordpress is not run.

本文标签: functionsCompletely Disable Wordpress RSS Feeds