Disable RSS Feed

时间:2019-12-02 作者:cindy

我想禁用rss提要,我的wordpress版本是5.2.4.

请参阅下面的代码以禁用rss提要。

 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);
根据书本,提要页面将显示wp\\u die页面。但它并没有表现出预期的效果。

它显示了这一点,请看屏幕截图,我不知道如何解决它。

enter image description here

2 个回复
SO网友:sanjay ojha

您需要在中定义HTTP响应代码wp_die 作用

wp_die( __(\'No feed available\'), \'\', 404 );
还可以设置自定义标题以获取HTML页面而不是xml页面。因此,代码应该如下所示。

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

SO网友:Eoin H

您是否尝试过使用remove\\u操作?

示例:

<?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 );
}
编辑:所以禁用它们并不会删除它们,要完全删除它们,还需要使用remove\\u操作。假设这就是你想要做的。

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