3

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.

enter image description here

3
  • Have you flushed rewrite rules and cleared any layers of caching?
    – WebElaine
    Dec 2, 2019 at 19:53
  • yeah,I have flushed the permalink and cleared the browser cach
    – cindy
    Dec 2, 2019 at 19:58
  • @Cindy Lu Hope this referrence helpful for you wpcaptain.com/blog/… Dec 3, 2019 at 10:16

2 Answers 2

2

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 );
}
1

have you tried using remove_action?

Example:

<?php
add_action('wp_head', 'remove_feeds_in_head', 1);

function remove_feeds_in_head() {
    remove_action( 'wp_head', 'feed_links', 2 );
    remove_action( 'wp_head', 'feed_links_extra', 3 );
}

EDIT: So disabling them doesn't remove them, to completely get rid of them, them you need to use remove_action aswell. Assuming this is what you want to do.

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', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'rsd_link');
// Add whatever other things you want to remove
2
  • yeah,but your function just remove the feed link from source code.
    – cindy
    Dec 3, 2019 at 2:12
  • @CindyLu I just updated my answer to give a little more clarity.
    – Eoin H
    Dec 3, 2019 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.