Images not showing on WordPress due to special characters is a mess
My site got infected with malwares. After I cleaned my site, I noticed that some of the Wordpress images are not showing due to a particular symbol issue. For example, this is the name of the image displayed on FTP
sandΓΒ-a-asd-123.jpg
But if I access the url via this path, it is still not available
mysite/imagepath/sandΓ-a-asd-123.jpg
Access only through this path
mysite/imagepath/sandΓ%C2%ADa-asd-123.jpg
Now what should I do? Should I change the names of all images in Wordpress DB or do I need to change the names via FTP?
thank
+3
source to share
1 answer
This wordpress feature works for me: remove all special characters from pic name. Hope it helps: D
add code to functions.php
function sanitize_filename_on_upload($filename) {
$ext = end(explode('.',$filename));
// Replace all weird characters
$sanitized = preg_replace('/[^a-zA-Z0-9-_.]/','', substr($filename, 0, -(strlen($ext)+1)));
// Replace dots inside filename
$sanitized = str_replace('.','-', $sanitized);
return strtolower($sanitized.'.'.$ext);
}
add_filter('sanitize_file_name', 'sanitize_filename_on_upload', 10);
0
source to share