0

We recently changed themes. The new theme uses different dimension thumbnails and I was a bonehead and deleted all previous thumbnail sizes. Deleting the thumbnail sizes results in many of the images in my posts throwing a 404 error as the specific size is no longer there. I have regenerated thumbnails to the new sizes using a plugin like Regenerate Thumbnails. The problem is, this does not replace the image SRCs in posts, so images are still not showing up.

Looking around, it looks like there is no "easy" solution to this problem. Rather, I need to manually go through the database and update the image SRCs. My question is, is there any function I can use to regenerate the SRCs on a per post basis? For example, if I were to pass the post_id to a function, could I somehow get all the images in that post and regenerate their SRCs? Maybe a function that simulates the "Add Media" or "Edit Media" button, but programmatically (i.e. if I were to manually go in and modify each image, it gets updated properly)?

Thanks!

3
  • @jgraup I'm looking for a solution that doesn't require me to run commands directly on tables. Commented Feb 15, 2016 at 3:19
  • There is nothing special about the content -- it is just a bunch of blog posts with images. I'm simply looking to replace the SRCs for thumbnails that display inside the post (the images are linked to the full image, so those are fine). Commented Feb 15, 2016 at 3:28
  • @jgraup I know enough PHP / MySQL to be able to manually parse through each post, find SRCs, and replace them with updated SRCs. That is not where I need help. I'm wondering if there is a DIFFERENT way to do this, aside from parsing the content of each post with a custom script. More specifically, as I said in the original post, I'm looking a function that automatically updates the SRCs if I pass the attachment ID to the function (if there is one). Commented Feb 15, 2016 at 3:45

1 Answer 1

0

If images src inside posts keep pointing to urls like "image-300x450.jpg", a SQL command can solve it. Something like

UPDATE wp_posts SET post_content = replace(post_content, '-300x250', '[new dimensions]');

Just find a safe part of the url to replace. Probably that is what I would try. Remembering to do the good old backup of your db before...

3
  • I plan on doing a mix of PHP / MySQL to fix the issue (although what you suggest won't work, as not all the images have the same width x height). Before I do that, however, I'm looking for a "safe" approach that allows me to simply regenerate the SRCs in the post. That is why I'm wondering if there is a function that does that. Commented Feb 15, 2016 at 0:48
  • I see... anyway, you could use it multiple times, for each of your previous thumb sizes. Commented Feb 15, 2016 at 1:37
  • Yeah, that is the last resort Commented Feb 15, 2016 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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