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’,
‘e’,’e’,’E’,’E’,’E’,’E’,’i’,’i’,’i’,’i’,’I’,’I’,’I’,’I’,’oe’,’o’,’o’,’o’,’o’,’o’,’o’,
‘O’,’O’,’O’,’O’,’O’,’u’,’u’,’u’,’U’,’U’,’U’,’c’,’C’,’N’,’n’,’-‘);

$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