When building a website, especially a new one, the biggest fear is having your content scraped. Often, the site scraping yours is older and has higher authority, so search engines might prefer indexing its articles and ignore yours. Therefore, we can implement a simple protection by delaying WordPress's RSS output time. If you don't want the RSS function, you can also disable it directly. Another function is to prevent situations where you publish an article, then modify the content, but the RSS feed still shows the unmodified version.
Delay RSS Output Code
Directly copy the code below and add it to your Theme's functions file, then save.
//推迟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 code above delays RSS 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 code below to modify the RSS update frequency (for RSS software), preventing RSS software from fetching 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
Method of Delaying RSS Output Timeonly provides some defense against websites that scrape via RSS. If someone is not scraping your website content via RSS, then this method is ineffective.
Completely Disable RSS Function
If you find RSS useless, you can also disable it directly. The method is as follows: Add the code below to the Theme's functions file. 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 homepage!' ) );
}
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.