当我们使用Wordpress建站的时候,在后台上传文件到媒体库当中,经常会出现中文或者其他特殊字符的问题,如何通过WordPress 上传媒体库文件重命名,今天分享这个修改方法技巧。
修改方法:
修改上传文件名为:年月日时分秒+两位随机数.扩展名
打开/wp-admin/includes/file.php文件
将
$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); // Move the file to the uploads dir.
替换为
$time=date(YmdH:i:s,time()+8*60*60); $file['name'] = $time..mt_rand(1,100)...$ext ; $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); // Move the file to the uploads dir.
保存覆盖源文件即可!