After a couple of hours searching the WP core I've lost hope finding this myself (for once).

Could someone guide me perhaps to where WordPress handles the incremental number when having duplicate file names during uploading?

As a side question. When handling questions like this, where and how would you start searching? AFAIK I've searched through every file containing file and upload.

1 Answer 1


The number is added in wp_unique_filename() in wp-includes/functions.php. You can prevent it by hooking into 'sanitize_file_name' and setting another file name.

You can find such functions and filters by following the code with your IDE. Most IDEs make functions clickable so you can go from their call to their declaration.

Here is an example from Eclipse PDT:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.