Support » Fixing WordPress » Upload Files – name with special characters

  • Hi friends,

    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 cára.pdf for exemple, it changes to cára.pdf at the uploads directory… but WP keeps its URL name cára.pdf

    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!


Viewing 1 replies (of 1 total)
  • Hello Cristiano, you can fix that by adding this script to your themes function.php file.

    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;

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

Viewing 1 replies (of 1 total)
  • The topic ‘Upload Files – name with special characters’ is closed to new replies.