已解决
公开

RT. 想要关闭网站 RSS 功能

1 人关注这个问题

    1 答案

    公开
    龙笑天 2021-12-28 17:14 最佳答案

    1.如果要彻底封禁网站全部 rss feed 功能,将下面代码加入 functions.php 里就行:

    /**
    * WordPress 如何禁用 RSS Feed - 龙笑天下
    * https://www.ilxtx.com/question/3108.html
    *
    * 封禁所有 feed 功能
    */
    function dr_qa_disable_all_rss_feed() {
    wp_die( 'Feeds have been disabled.', 'WordPress Error', array('response'=>410) );
    }
    add_action('do_feed', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_rdf', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_rss', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_rss2', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_atom', 'dr_qa_disable_all_rss_feed', 1);

    2.如果是只封禁评论的 rss feed 功能的话,将下面代码加入 functions.php 里就行:

    /**
    * WordPress 如何禁用 RSS Feed - 龙笑天下
    * https://www.ilxtx.com/question/3108.html
    *
    * 禁止评论 feed
    */
    add_filter( 'feed_links_show_comments_feed', '__return_false' );
    function dr_qa_disable_comments_rss_feed($is_comment_feed) {
    if( $is_comment_feed ){
    wp_die( 'Feeds for comments have been disabled.', 'WordPress Error', array('response'=>410) );
    }
    }
    add_action('do_feed', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_rdf', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_rss', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_rss2', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_atom', 'dr_qa_disable_comments_rss_feed', 1);

    3.对于 Dragon 主题来说,封禁了 feed 功能后,还要隐藏掉 feed 按钮图标等。也很简单,将下面代码加入到“主题设置-头部”里的“Header 中加载自定义代码”里,保存主题设置,然后清理各种缓存,OVER:

    <style>#footer-links-icons span.footer-rss-link, #focus-slide .focus-title.feed,#focus-slide .focus-content.feed{display:none !important;}</style>

    相关参考:
    WordPress 技巧:禁用 RSS Feed - WordPress 果酱
    如何彻底移除并关闭 WordPress 的 RSS feed - 露兜即刻

    #
    公开
    龙笑天 2021-12-28 17:14 最佳答案

    1.如果要彻底封禁网站全部 rss feed 功能,将下面代码加入 functions.php 里就行:

    /**
    * WordPress 如何禁用 RSS Feed - 龙笑天下
    * https://www.ilxtx.com/question/3108.html
    *
    * 封禁所有 feed 功能
    */
    function dr_qa_disable_all_rss_feed() {
    wp_die( 'Feeds have been disabled.', 'WordPress Error', array('response'=>410) );
    }
    add_action('do_feed', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_rdf', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_rss', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_rss2', 'dr_qa_disable_all_rss_feed', 1);
    add_action('do_feed_atom', 'dr_qa_disable_all_rss_feed', 1);

    2.如果是只封禁评论的 rss feed 功能的话,将下面代码加入 functions.php 里就行:

    /**
    * WordPress 如何禁用 RSS Feed - 龙笑天下
    * https://www.ilxtx.com/question/3108.html
    *
    * 禁止评论 feed
    */
    add_filter( 'feed_links_show_comments_feed', '__return_false' );
    function dr_qa_disable_comments_rss_feed($is_comment_feed) {
    if( $is_comment_feed ){
    wp_die( 'Feeds for comments have been disabled.', 'WordPress Error', array('response'=>410) );
    }
    }
    add_action('do_feed', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_rdf', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_rss', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_rss2', 'dr_qa_disable_comments_rss_feed', 1);
    add_action('do_feed_atom', 'dr_qa_disable_comments_rss_feed', 1);

    3.对于 Dragon 主题来说,封禁了 feed 功能后,还要隐藏掉 feed 按钮图标等。也很简单,将下面代码加入到“主题设置-头部”里的“Header 中加载自定义代码”里,保存主题设置,然后清理各种缓存,OVER:

    <style>#footer-links-icons span.footer-rss-link, #focus-slide .focus-title.feed,#focus-slide .focus-content.feed{display:none !important;}</style>

    相关参考:
    WordPress 技巧:禁用 RSS Feed - WordPress 果酱
    如何彻底移除并关闭 WordPress 的 RSS feed - 露兜即刻

    #1

    来提交答案

    扫一扫二维码分享
    ×