简体   繁体   中英

Images not showing on wordpress because of special characters mess

My site was infected with malwares. After I cleaned my site, I noticed that some of wordpress images were not showing because of special character issue. For example this is the image name as displayed on FTP

sandí-a-asd-123.jpg

But if I access URL through this path it is still not accessible

mysite/imagepath/sandÃ-a-asd-123.jpg

It is only accessible through this path

mysite/imagepath/sandÃ%C2%ADa-asd-123.jpg

Now what should I do here? Should I change all images names in wordpress DB or should I change names through FTP?

Thanks

This wordpress function works for me: remove all special characters from pic name. Hope it helps :D

add code in 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM