{"id":1944,"date":"2012-09-17T10:35:43","date_gmt":"2012-09-17T15:35:43","guid":{"rendered":"http:\/\/www.uv.mx\/personal\/gvera\/?p=1944"},"modified":"2012-10-02T11:51:01","modified_gmt":"2012-10-02T16:51:01","slug":"wordpress-remove-special-characters-from-uploaded-files","status":"publish","type":"post","link":"https:\/\/www.uv.mx\/personal\/gvera\/2012\/09\/17\/wordpress-remove-special-characters-from-uploaded-files\/","title":{"rendered":"WordPress: Remove Special Characters From Uploaded Files"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1952\" title=\"subir-archivo-acento\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2012\/09\/subir-archivo-acento.gif\" alt=\"\" width=\"712\" height=\"397\" \/><br \/>\nDuring my experience with WordPress I have found out users who are not familiar with Internet, tends to write filenames with special characters and even white spaces. It is almost impossible to teach them not to do that because they have been doing it all their life.<\/p>\n<p>The problem with accents and WordPress appears when you are using URL Rewriting and your rules don&#8217;t consider special Latin characters. You will get a Not Found message when trying to access these files.<\/p>\n<p>WordPress do not automatically remove Latin characters like accents (\u00e1, \u00e9, \u00ed, \u00f3, \u00fa), but it comes with a very handy internal function called <a title=\"remove_accents\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/remove_accents\" target=\"_blank\">remove_accents<\/a>. So, if you want to make sure Latin characters are removed from file name when uploaded, you can use this in your functions.php file:<!--more--><\/p>\n<p><code>add_filter('sanitize_file_name', 'sa_sanitize_spanish_chars', 10);<br \/>\nfunction sa_sanitize_spanish_chars ($filename) {<br \/>\nreturn remove_accents( $filename );<br \/>\n}<br \/>\n<\/code><\/p>\n<p>The remove_accents() function is located in wp-includes\/formatting.php.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>During my experience with WordPress I have found out users who are not familiar with Internet, tends to write filenames with special characters and even white spaces. It is almost impossible to teach them not to do that because they have been doing it all their life. The problem with accents and WordPress appears when&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[11,36,12],"class_list":["post-1944","post","type-post","status-publish","format-standard","hentry","category-wordpress-2","tag-articulos-2","tag-php","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts\/1944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/comments?post=1944"}],"version-history":[{"count":0,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts\/1944\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/media?parent=1944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/categories?post=1944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/tags?post=1944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}