自定义WordPress媒体文件上传时间

WPOCN WordPress教程评论43阅读模式

WordPress上传媒体文件会自动以当前时间为时间戳,如想自定义这个时间戳,可以将下面的代码添加添加到当前主题函数模板 functions.php 中:

function custom_upload_time() {
	// 获取自定义上传时间
	$custom_time = strtotime('2023-01-01 00:00:00'); 
	return $custom_time;
}
 
add_filter( 'wp_insert_attachment_data', function( $data, $postarr ) {
	$custom_time = custom_upload_time();  
	// 设置自定义时间
	$data['post_date'] = date( 'Y-m-d H:i:s', $custom_time );
	return $data;
}, 10, 2 );

之后,上传媒体文件会以设定的时间为时间戳。

文章末尾固定信息

weinxin
我的微信
我的微信
微信扫一扫
 
WPOCN
  • 本文由 WPOCN 发表于 2023年7月3日17:16:37
  • 转载请务必保留本文链接:https://www.tghello.com/5177.html

发表评论