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-2000x2000.jpg"><img ... /></a>

Does anyone know how this could be done (using code or some plugin)?