Take the 2-minute tour ×
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
add comment

3 Answers

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
add comment

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: http://posterous.jefflundberg.com/make-wordpress-image-link-to-large-image-inst

share|improve this answer
add comment

You might find this slightly related thread interesting:

http://wordpress.stackexchange.com/questions/3184/can-images-be-automatically-compressed/

share|improve this answer
add comment

Your Answer

 
discard

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.