有时候一些图片,上传到WordPress的媒体库之后还是会保留原来的名字
其实蛮不美观的,而且在一定程度上说会有安全风险
今天记录一下让WordPress上传文件自动重命名:
老规矩
老规矩
functions.php
加上:-
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter'); function custom_upload_filter($file) { $info = pathinfo($file['name']); $ext = '.' . $info['extension']; $md5 = md5($file['name']); $file['name'] = $md5.$ext; return $file; }