0

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-2000x1500.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.)

  • can you tell me what the code in your theme php file looks like? – rudtek Sep 5 '17 at 22:35
0

You can use the get_the_post_thumbnail_url explained here

So, the code would be

<a href="<?php echo get_the_post_thumbnail_url(get_the_ID, array (2000, 1500) ) ?>" >....... </a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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