I have a WordPress website with existing content and images. Currently, images in posts link to the original media file. I’d like to modify this, such that they link to a resized version of the image (e.g., max 2000x2000 px). Preferably, this should be done by some filter that is applied when rendering the page, so I don’t have to edit the existing links in my posts.
E.g., I want this:
<a href="/wp-content/uploads/file.jpg"><img ... /></a>
to be converted into this:
<a href="/wp-content/uploads/file-2000x20002000x1500.jpg"><img ... /></a>
Does anyone know how this could be done (using code or some plugin)?
One thing that makes it challenging, is that the resized image don’t have a constant size (e.g., 2000x2000 px). Because I want the images to be soft proportional cropped, they can get a different size. (E.g., a 4000x3000 px image would be resized to 2000x1500 px.)