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

Read More
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

Related posts

1 comment

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

    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);
    

Comments are closed.