Clean filenames

Safe uploaded file names — automatic accent and space cleanup

Clean filenames intercepts every uploaded file (images and other media) before it’s saved and converts accents, spaces and special characters into a safe form — lowercase, hyphens, no diacritics. The original name is preserved as the attachment title.

Key features

  • Works on both classic and AJAX/drag-and-drop uploads (`wp_handle_upload_prefilter` and `sideload_prefilter`)
  • Custom transliteration built on WordPress core’s `remove_accents()`
  • Configurable scope — clean images only, or every file type
  • The original file name is saved as the attachment title, so nothing is lost
  • No spaces, uppercase letters or accented characters in the media URL

How it works

The `wp_handle_upload_prefilter` hook (and its sideload variant for AJAX uploads) catches the file before it’s physically saved to disk. The module runs the name through `remove_accents()` and its own filter, then lowercases the result and replaces spaces with hyphens.

The original name is temporarily stored in a transient tied to the current user and applied as the `post_title` once the attachment is created, so the media library still shows a readable name even though the URL is clean.

Frequently asked questions

Do I lose the original file name?
No, it’s saved as the attachment title in the media library — you’ll still see it after the URL is cleaned.
Does it work on drag-and-drop uploads too?
Yes, the module hooks both the classic upload form and the AJAX/sideload process.
Can I clean only images, not all files?
Yes, the scope (images / everything) is configurable in the module.