How to fix WordPress media upload special characters

I just realized that when a upload a file that has a name with special characters, its name is changed in the uploads directory, but not in his URL name… so I get a 404 page error…

I mean, if the file name is  ” – WordPress-Framework-Theme” for exemple, it changes to cára.pdf at the uploads directory… but WP keeps its URL name “-–-WordPress-Framework-Theme“.

Wordpress media upload special characters

Is there a way to solve it? WP could change both, the file name and the file URL or change neither… but if it changes just one of them, I have a big problem!

For fix this WordPress media upload special characters:

Go to your current theme using

Open functions.php

Add new code after <?
////////////////Replace all characters has special format///////////////////
/* $accents_search = array('á','à','â','ã','ª','ä','å','Á','À','Â','Ã','Ä','é','è',

$accents_replace = array(‘a’,’a’,’a’,’a’,’a’,’a’,’a’,’A’,’A’,’A’,’A’,’A’,’e’,’e’,

$str = str_replace($accents_search, $accents_replace, $str);

add_filter(‘sanitize_file_name’, ‘sa_sanitize_spanish_chars’, 10);
function sa_sanitize_spanish_chars ($filename) {
return remove_accents( $filename );
} */

add_filter(‘sanitize_file_name’, ‘sa_sanitize_spanish_chars’, 10);

function sa_sanitize_spanish_chars ($filename) {
$spanish_chars = array( ‘/á/’, ‘/é/’, ‘/í/’, ‘/ó/’, ‘/ú/’, ‘/ü/’, ‘/ñ/’, ‘/Á/’, ‘/É/’, ‘/Í/’, ‘/Ó/’, ‘/Ú/’, ‘/Ü/’, ‘/Ñ/’, ‘/º/’, ‘/ª/’, ‘/–/’ );
$sanitized_chars = array(‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘u’, ‘n’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’, ‘U’, ‘N’, ‘o’, ‘a’, ”);
$friendly_filename = preg_replace($spanish_chars, $sanitized_chars, $filename);
return $friendly_filename;
////////////////Replace all characters has special format///////////////////

You can check my website that is working and wordpress and its already fixed.

Add Comment