下面的代码加到主题文件夹下的functions.php文件中。

上传文件会自动根据时间重命名,最后2位为(10-99)随机数字。

  • add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' );
  • function custom_upload_name( $file )
  • {
  • if ( !$ext )
  • $ext = ltrim(strrchr($file['name'], '.'), '.');
  • $file['name'] = date("YmdHis").rand(10,99).'.'.$ext;
  • return $file;
  • }复制代码

就这样了。