Support » Fixing WordPress » Regenerating HTML code

  • bst7

    (@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.

    Thanks

    William

    (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

    (@joyously)

    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.

    bst7

    (@bst7)

    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

    (@joemcgill)

    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?

    bst7

    (@bst7)

    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:

    a:4:{s:4:”file”;s:27:”20130529_L1101623-50×50.jpg”;s:5:”width”;i:50;s:6:”height”;i:50;s:9:”mime-type”;s:10:”image/jpeg”;}s:6:”medium”;
    a:4:{s:4:”file”;s:29:”20130529_L1101623-375×249.jpg”;s:5:”width”;i:375;s:6:”height”;i:249;s:9:”mime-type”;s:10:”image/jpeg”;}s:12:”medium_large”;
    a:4:{s:4:”file”;s:29:”20130529_L1101623-768×511.jpg”;s:5:”width”;i:768;s:6:”height”;i:511;s:9:”mime-type”;s:10:”image/jpeg”;}s:5:”large”;
    a:4:{s:4:”file”;s:29:”20130529_L1101623-525×349.jpg”;s:5:”width”;i:525;s:6:”height”;i:349;s:9:”mime-type”;s:10:”image/jpeg”;}s:12:”ws-large-620″;
    a:4:{s:4:”file”;s:29:”20130529_L1101623-620×412.jpg”;s:5:”width”;i:620;s:6:”height”;i:412;s:9:”mime-type”;s:10:”image/jpeg”;}s:32:”twentyseventeen-thumbnail-avatar”;
    a:4:{s:4:”file”;s:29:”20130529_L1101623-100×100.jpg”;s:5:”width”;i:100;s:6:”height”;i:100;s:9:”mime-type”;s:10:”image/jpeg”;}s:17:”ws-two-column-175″;

    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?

    Tahnks

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