Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
Do they link to the image directly, or to the attachment page that contains the image? – Jan Fabry Nov 2 '10 at 9:28
Hi Jan, the theme links directly to the image. – grm Nov 2 '10 at 12:31

3 Answers 3

up vote 2 down vote accepted

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 with wp_get_attachment_image_src() by passing the requested size ("large").

share|improve this answer
Great answer Jan. Got it working on a test installation. Thanks. – grm Nov 2 '10 at 20:39

Here’s a solution I came up with using the *attachment_fields_to_edit* hook in a filter. It allows you to modify the HTML generated for the admin screen to add a new image. It will not fix or alter any existing posts, but it will make the large image size the default when you add a new image.

Details here:

share|improve this answer

You might find this slightly related thread interesting:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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