How can I best make WP link to the large version of the image in all posts (instead of the original one) without modifying all the data in the database? I’m probably looking for the best filter to attach to.
Leave a Reply
You must be logged in to post a comment.
You can modify the content that is displayed on the site by hooking in to the
the_content
filter. However, this is where the hard work starts. You need to identify all the images, figure out the links to the large sizes, and replace them. This could be a costly operation, so you might want to save the post back to the database and set a (hidden) meta key to indicate you don’t have to do it again next time.Now, some hints on how to do this: to get info on the attached images, you use
get_children()
and specify you only want attachments:get_children($post->ID, array('post_type' => 'attachment'))
. Attachments are stored like posts, and you can request different sizes withwp_get_attachment_image_src()
by passing the requested size ("large"
).All you have to do is to go into the HTML version of your post and add a little simple code – don’t panic if you think you don’t understand code.
The middle bit of this is what already exists for your image. The bit above and the at the end is what you add. The source for image (in this case src=”https://bdaiken.files.wordpress.com/2016/01/wp-header.jpg’ has to be pasted in from the middle html into the new html – don’t copy the ‘?’.