I have a site that has lots of images that have spaces in them.

I am not sure if the spaces got there because of how the old theme uploaded images or if it was the tool I used to migrate the site from one wordpress network to another but the result is that the filename with space included is being output to html so the images are breaking.

I renamed all the files with a bash script:

for f in *\ *; do mv "$f" "${f// /-}"; done

Then I updated all the names in post table:

UPDATE `wpds_16_posts` 
SET `post_title` = REPLACE(`post_title`, ' ', '-' )
where `post_type` = 'attachment'

Now I need to update all references to the images as all the images on the site are still broken with the space in the name.

Where are these references? I am at a bit of a loss to find them.

Edit: seems like they are in post meta. This looks like it will be easier to just remake site from scratch.

PS. Found cause of all this bother. The theme was creating responsive image variations with spaces in them but escaping it to final output. If you ever try to change theme or export data it breaks. Worth keeping an eye out for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.