目录
隐藏
我的推荐方法如下
在主题中添加自定义函数实现
在网站当前使用的主题模板中(一般在主机中的文件路径为 /wp-content/themes/模块文件名\)下的 functions.php 文件中加入以下代码:
function wpmaker_rename_upload_file_prefilter($file){
$time=date("Y-m-d");
$file['name'] = $time."".mt_rand(1,100).".".pathinfo($file['name'] , PATHINFO_EXTENSION);
return $file;
}
add_filter('wp_handle_upload_prefilter', 'wpmaker_rename_upload_file_prefilter');
这个方法保存后的文件名称为年月日时分秒+随机数字。不显示时分秒,改为$time=date(“Y-m-d”); 显示时分秒为 $time=date(“Y-m-d H:i:s”)。
比如上载一个带中文的JPG文档,自动处理成如下文件名。
参考阅读
WordPress上传图片自动重命名的几种办法
https://zhan.leiue.com/wordpress-rename-images.html
WordPress中文名、数字名图片上传自动重命名代码
http://www.php.cn/php-weizijiaocheng-356174.html
WordPress上传图片自动重命名的方法
http://www.jb51.net/cms/145470.html
解决WordPress图片中文命名乱码问题(批量重命名)
https://www.wpdaxue.com/wordpress-images-chinese-name-garbled.html
WordPress上传中文名图片自动重命名
http://www.chenxingweb.com/wordpress-uploads-zh-move.html
WordPress中文图片自动重命名的3种方法汇总
http://www.wpyou.com/wordpress-chinese-file-renaming.html