Home Experience & Tips Sharing Standard Post

Standard Post

Delay WordPress RSS Feed Output Time_Completely Disable RSS Function

Building a website, especially a new one, the biggest fear is being scraped by others. Because often the scraper site is older and has higher authority than yours, and search engines may prefer to index its articles while ignoring yours. So we can do a simple protection by delaying the RSS output time of WordPress. If you don't need the RSS function, you can also disable it directly. Additionally...

Updated on June 16, 2021 About 4 minutes read
推迟WordPress的RSS输出时间_彻底关闭RSS功能

Building a website, especially a new one, the biggest fear is being scraped by others. Because often the scraper site is older and has higher authority than yours, and search engines may prefer to index its articles while ignoring yours.

So we can do a simple protection by delaying the RSS output time of WordPress. If you don't need the RSS function, you can also disable it directly.

Another function is to prevent the RSS content from remaining unmodified after you publish an article and then modify the content.

Delay RSS Output Code

Directly copy the following code snippet and add it to your theme functions file, then save it.

//推迟RSS输出 https://blog.naibabiji.com/skill/tui-chi-wordpress-rss-shi-jian.html
function publish_later_on_feed($where) {
    global $wpdb;
    if ( is_feed() ) {
        $now = gmdate('Y-m-d H:i:s');
        //RSS输出延迟多久由$wait的值控制
        $wait = '2';
        //输出类型MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
        $device = 'DAY';
        $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
    }
    return $where;
}
add_filter('posts_where', 'publish_later_on_feed');

The above code delays RSS content output by two days. If you want to modify it yourself, please adjust according to the comments within the code.

Set RSS Update Frequency Code

Additionally, you can use the following code to modify the RSS update frequency (for RSS software), preventing RSS software from scraping data every hour.

// 每6小时
add_filter( 'rss_update_period', function() {return 'hourly';} );
add_filter( 'rss_update_frequency', function() {return '6';} );

Finally, the method introduced in this articleBy delaying RSS output timeonly provides some defense against websites that scrape via RSS. If others are not scraping your website content through RSS, then this method is ineffective.

Completely Disable RSS Function

If you think RSS is useless, you can also disable it directly. The method is as follows:

Add the following code to the theme functions. Beginners can refer to:Safe Method to Add Code to the functions.php File: Code Snippets

// 完全禁用WordPress RSS功能
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);

// 移除网页RSS代码
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );

Of course, you can also use theDisable Feedsplugin to directly disable RSS subscriptions.

Rate this article post
Previous Implement Security Measures to Avoid WordPress Websites Being Hacked Continue reading content around the same timeline. Next Safe Method to Add Code to the functions.php File: Code Snippets View the next related tutorial or experience.

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: