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

    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:

    View post on imgur.com

    Anyone know what I’m doing wrong?

    David.

    • This topic was modified 2 years, 8 months ago by David Adams.
    • This topic was modified 2 years, 8 months ago by David Adams.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    wp_die() is not the way to do this. See https://www.wpbeginner.com/wp-tutorials/how-to-disable-rss-feeds-in-wordpress/ for a code example.

    Thread Starter David Adams

    (@tictag)

    @sterndata Interesting, I actually used that article as the basis for my code.

    David.

    Dion

    (@diondesigns)

    Using actions/filters means WordPress is executed, which wastes server resources. You can instead use a rewrite rule to block WP feeds…here’s something generic:

    RewriteRule ^feed/$ - [R=400,L]

    It would be placed above the WordPress rewrite block to insure it is processed first. You may need RewriteBase and RewriteEngine directives depending on your configuration. Adjust the HTTP error to whatever you think is best. You can also use an ErrorDocument directive to display a custom error message.

    Thread Starter David Adams

    (@tictag)

    @diondesigns A valid point and, as you say, would require fewer server resources, but unfortunately not all website hosting providers provide access to the root .htaccess file (e.g. Flywheel). Unfortunately, I’m stuck with WordPress functions.

    But anyway, my query was more about why wp_die() wasn’t rendering the pretty HTML page I’ve seen on so many articles. I even tried creating a fresh Local site and received the same knarley XML tree page. Just feel like I’m missing something.

    David.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    wp_die() causes the HTML output to stop, breaking the page. The 404 solution allows the page build to continue.

    Thread Starter David Adams

    (@tictag)

    Agreed that the ‘404 solution’ (Method 1) is an option, and maybe even a better one.

    I’m trying to follow a ‘minimal code’ principle with this website (cyber security is a big deal for this company) and adding a plugin with lots more code than I actually need is contrary to that principle. Method 2, therefore, was the preferred solution and in that very article towards the bottom it shows the pretty HTML page I’m supposed to get when using the wp_die() function … I’m just not getting that and have no idea why.

    Has the wp_die() function changed recently? Am implementing it incorrectly?

    I’m on v5.9.2 of WordPress.

    David.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    wp_die is doing exactly what it’s supposed to do — stop the current PHP code dead in its tracks.

    Thread Starter David Adams

    (@tictag)

    @sterndata According to the WordPress developer reference (https://developer.www.ads-software.com/reference/functions/wp_die/), the difference between the die() and wp_die() functions is that the latter renders a HTML page with an error message and allows for a customisable response code prior to calling die().

    I am not a developer, not even close, but it seems that WordPress is supposed to be doing one thing, but is actually doing something else. Can we agree on that?

    David.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    No, it’s doing EXACTLY what it’s supposed to do.

    Thread Starter David Adams

    (@tictag)

    OK, well, I’m sorry to have bothered you, @sterndata . Looks like this one is just beyond my capability to understand. I’m not the brightest spark. Thank you for your input on this.

    David.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    No bother; it’s just how it is. ??

    wp_die( $string ); outputs $string then pulls the plug on further execution.

    Thread Starter David Adams

    (@tictag)

    @sterndata Yes, that’s exactly what I want, and exactly what I am not getting.

    I think confusion is creeping in on exactly how $string is outputted – but we both agree that it should be, right? My understanding is that it is output in a HTML page like the one towards the bottom of the article you linked me to. All I’m getting is some knarley XML tree.

    Are we now on the same page?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    The page itself is XML and the RSS feed starts with XML declarations. wp_die prevents the XML from completing into something that’s “good” XML. Don’t use wp_die() for this.

    With that, I’m done. ??

    Thread Starter David Adams

    (@tictag)

    @diondesigns Might have found a workaround to implementing your solution. Flywheel allows its customers to create redirects via their admin portal/dashboard feature. So I should be able to use that to redirect ./feed/ to the homepage.

    No WordPress needed here and, perhaps waaaay more importantly, no wp_die() either! ??

    Thanks for your help, guys. Genuinely appreciated.

    David.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Completely Disable WordPress RSS Feeds’ is closed to new replies.