Rename Files During Upload within WordPress Backend

The passage is telling you how to rename the file name automatically by WordPress (without using any plugins).

Warning: To apply this hack, you'll have to edit one of WordPress's core files. Keep in mind that it is never recommended. This hack should be redone if you upgrade WordPress.

open the wp-admin/includes/files.php file, and go to line 324 (approximately here). You'll see the following:

$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );

Change it as follows:

$time_filename = "";
if ($time) {
    $time_filename = $time;
    $time_filename = str_replace(["-", " ", ":"], "", $time_filename);
} else {
    $time_filename = date("YmdHis");
}
$filename = $time_filename . dechex(mt_rand(65536, 1048575)) . "." . $ext;

And the file you upload will automatically be renamed as 20130218180064x268c.ext.

Contact Us
  • Tencent AI Lab, Shenzhen, China
  • cshzxie [at] gmail [dot] com