Support » Fixing WordPress » Regenerating HTML code

  • bst7


    I’ve switched themes from a custom theme to 2017 theme. As part of this transition, I also want to remove alot of unnecessary image sizes that are taking up alot of room on my server.

    In order to do this, I removed and regenerated thumbnails. However, this breaks ALL of my existing posts. I want to just have these image sizes (in pixel widths):
    525w, 375w,768w and 620w for compatability

    However the srcset for tag has these additional sizes:
    …/uploads/2014/08/01-20140813-L1004852-980×654.jpg 980w,
    …/uploads/2014/08/01-20140813-L1004852-780×520.jpg 780w,
    …/uploads/2014/08/01-20140813-L1004852-300×200.jpg 300w,
    …/uploads/2014/08/01-20140813-L1004852-175×116.jpg 175w”

    After doing some research, I found these notes:

    Responsive Images in WordPress 4.4

    which states:
    Note that for compatibility with existing markup, neither srcset nor sizes are added or modified if they already exist in content HTML.

    But, this is a problem for me, as I want to get rid of these images, but as they are being included in the srcset I can’t for existing posts….

    Ideally, I would like to tell wordpress to regenerate all of the HTML pages, using the current set of image sizes. I have actually fixed any minor recompatability problems, and I would rather do this than have some kind of runtime modification of the HTML code to filter out unwanted images.

    Currently, I’m regenerating the complete set of thumbnails for all of these sizes, as I can’t find any other solution at this point.



    (PS – if this is moderated and I’ve posted in the wrong forum, can you please email with details about where I should post! Thanks! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • Joy


    The srcset is generated when the page is viewed. The compatibility note is referring to srcset or sizes that are in img tags already (put there by the user or editor or a plugin). If you use the Regenerate Thumbnails plugin, it fixes the img tags in your content.
    The database has size information on each attachment. Any changing of image sizes needs to update that information.
    You can use a plugin like Dynamic Image Resize, which only generates the sizes when they are used, instead of having them all there all the time.



    Hi Joy,

    Thanks for your comments. That is how I thought it would work too, but it doesn’t.

    All that I see that Regenerate Thumbnails does is to regenerate the images based on the registered sizes I have on my site at that time. It does not – as my post above describes – adjust any of the parameters that are used to generate the HTML… From somewhere – I don’t know where – WP has kept or cached a knowledge of the images sizes for each image in the DB, so that is why I get the above HTML where the IMG srcset is generating a list that references that no longer exist.

    So, your comment though is interesting:
    “The database has size information on each attachment. Any changing of image sizes needs to update that information.”

    The regenerate plugin is not touching that information, which is my problem.

    Do you know of anyway that I can get access to that cache in the database and reset it?

    Basically, I just want the HTML’s IMG srcset that is generated to only include currently valid image sizes, with no reference to previous sizes.

    • This reply was modified 2 years ago by bst7.
    Joe McGill


    Hi @bst7,

    As @joyously correctly suggested above, WordPress adds the srcset attribute to images in your posts when the page is created. It does not save those values in the content in the database to avoid exactly the situation you’re describing, so it’s a unexpected that you would see a page with a srcset that includes images that are no longer available on your server after regenerating.

    I expect that one of two things are happening. Either a) you have a caching plugin installed that saved the old markup from before the time when the images are regenerated, or b) your database still includes the deleted files in the attachment metadata for those attachments. To check the latter, can you find the attachment id for one of the images that isn’t working and use either wp_get_attachment_metadata() in your site or look up the value in the post_meta table of your database where the meta key is _wp_attachment_metadata and the ID matches the attachment ID?



    Hi Joe,

    Thanks for your reply. Yes, this was the behaviour I expected as well, so I was surprised to see it behave differently.

    I added one of the images I know demonstrates this problem to a new page. I deleted all of the thumbnails, and regenerated the smaller set (375w,575w,768w). I verified the server ONLY has these sizes – and in the Regenerate Plugin itself, it only tells me it should only generate those sizes. Same problem, I still see the srcset with all of these additional sizes.

    There is no cache’ing that I can see on the website. No cache plugin (I deleted the one that was installed previously, but that hasn’t been running for years).

    So, I’m looking through the database, and I see alot of values for attachment_metadata as you suggested, all with size info that I no longer want, as well as sizes I do want.. This is an abbreviated list:


    I’ve no idea how to clean this up!

    Can I delete all of this, delete all of the thumbnails, and then regenerate them?

    Or, any suggestions?


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Regenerating HTML code’ is closed to new replies.