When building a website, especially a new one, the biggest fear is being scraped. Often, sites that scrape yours are older and have higher authority, so search engines may prefer indexing their articles over yours, ignoring yours. Therefore, we can implement simple protection by delaying WordPress's RSS output time. If you don't want the RSS function, you can also disable it directly. Another feature is to prevent situations where you modify content after publishing an article, leaving the RSS content unmodified.
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 article
By 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 find RSS not useful, you can also disable it directly. The method is as follows: Add the code below 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 the
Disable Feedsplugin to directly disable RSS subscriptions.
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.