Skip to content

Removing accented characters from file names uploaded in WordPress

Warning: this article was written over 10 years ago, some information may be out of date.

For example, when moving the site from one server to another, it may happen that there are problems with the encoding of file names uploaded via WordPress, especially if many people are using the site and have the terrible habit of using files with accented characters and spaces.
WordPress already automatically removes spaces, but for accented characters, there is a trick: use the same function WordPress uses to clean up post titles and create slugs.

add_filter( 'sanitize_file_name', 'sanitize_accents_on_upload', 10 );

function sanitize_accents_on_upload( $filename ) {
return remove_accents( $filename );
}

Previous article

Next article

Thread

Leave a comment

Your email address will not be published.