0

I'm using the classic editor and here are my default settings for images:

enter image description here

In a post, I want all inserted images to be linked to the medium size URL instead of the full sized URL, which appears to be how WP sets it when choosing link to 'Media File'.

Ideally, I want a way to set it for existing and future posts. So far I've found 2 possible ways:

  1. The image_send_to_editor filter: I str_replace the $url with the medium size URL. This works for future images that are added to the posts but not for existing images.

  2. The the_content filter: This would work for existing posts but I'm not sure if I should go with this.

Is there a better approach out there, and which do you recommend?

1 Answer 1

0

You can use wp_get_attachment_link(), function if you pass the size argument as medium you will get the medium size image link.
https://codex.wordpress.org/Function_Reference/wp_get_attachment_link

1
  • How does this work for all images inserted in a post, whose content is shown by WP using the_content()? This appears to only be relevant when one is echoing a specific image.
    – sgro
    Commented Jul 5, 2019 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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