如果我们懂运营的朋友应该知道,有些时候搜索引擎的体验和时间戳有关系的。我们有些旧文会不定期的调整发布日期,这里有没有一个自动的办法实现日期的更新?在这里,我们可以用这个代码实现,比如我们访问的旧文章,可以自动的更新到当前的日期。
// by itbulu.com 整理。
function wpxss_update_post_timestamp_on_view() {
if (is_single()) { // only update for single post pages
$post_id = get_the_ID();
$current_time = current_time('mysql');
$post_data = array(
'ID' => $post_id,
'post_modified' => $current_time,
'post_modified_gmt' => get_gmt_from_date($current_time),
);
wp_update_post($post_data);
}
}
add_action('the_post', 'wpxss_update_post_timestamp_on_view');
但是这个也有一个问题,如果文章多且访客多,势必会给服务器和网站带来很大的压力的。
本文出处:老蒋部落 » WordPress设置访问页面的时候自动更新发布日期 | 欢迎分享( 公众号:老蒋朋友圈 )