0

I tried to use the Enable Media Replace Plugin to replace some images on my site with updated versions. There is an option to update all instances where the file is used on the site, but this only applies to the original image. WordPress automatically generates several different sizes of each image and renames them with -img-size.jpg. These resized images' names are not being updated by the plugin, so anywhere that they are used (like, everywhere) is now a broken image. I looked at the post HTML and everything looks like:

<a href="example.com/wp-content/uploads/2013/12/newfilename.jpg">
    <img class="size-medium wp-image-1172 alignright" alt="old file name" src=example.com/wp-content/uploads/2013/12/oldfilename-300x168.jpg" width="300" height="168" />
</a>

Clicking on the broken image will take you to the updated image, but the image is broken in the post. For example, here's a post I replaced images on.

Is there a MySQL command I can use that will turn oldfilename-300x168.jpg into newfilename-300x168.jpg in the img src tag for all instances? Doing it manually would take forever and I know NOTHING about jquery/javascript. It seems like I should be able to use replace() but I'm just not sure how to word it to work for all my images.

1

This feels like it is too link-heavy for an answer, but oh well. You can either use the Velvet Blues Update URLs plugin or the Serialized Search and Replace script. Either will allow you to search for a string in the database and change it to something else. The former lets you do it from your dashboard, whereas the latter requires you to FTP the file to your server and then navigate to that new page.

  • The first plugin says it replaces URLS, so I don't think that will do what I'm looking for, which is just to replace filenames. The second one looks like it may work but what do I tell it to replace with what? Is there something I can type in that will make it pull the correct filename from wherever it is? Like if href= correct.jpg, can I tell it to replace img src= wrong-300x168.jpg with correct-300x168.jpg? I apologize if I'm not being clear enough with the question, I'm not sure the proper way to explain it. – user3262092 Feb 2 '14 at 17:07
  • Don't be limited by the plugin name. It changes strings anywhere in the site. The most obvious use is for changing URLs after a site move. Unfortunately, I don't fully understand what you are asking, but If you your resized images didn't regenerate based on your new image, maybe you actually need to Regenerate Thumbnails? – helgatheviking Feb 2 '14 at 18:03
  • When I replaced the images, Wordpress generated new resized images. I used filezilla to check that because initially i thought that was the problem. The new files are there, but those URLs using the resized images weren't updated – user3262092 Feb 2 '14 at 20:38
  • There doesn't seem to be any solution that doesn't involve going through my posts one by one. I have found a broken links plugin that I will use to update the names. Thank you for the help! – user3262092 Feb 2 '14 at 21:26
  • If you need to change a lot of strings.... well yeah, I think you might be stuck. Sorry I don't have the SQL knowledge to help more. Maybe that's a question for regular stackoverflow. – helgatheviking Feb 2 '14 at 22:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.