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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    
You might find this slightly related thread interesting: wordpress.stackexchange.com/questions/3184/… – Denis de Bernardy Nov 2 '10 at 12:35
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

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.

<a href="https://bdaiken.files.wordpress.com/2016/01/wp-header.jpg" rel="attachment wp-att-99">

<img class="alignnone  wp-image-99" src="https://bdaiken.files.wordpress.com/2016/01/wp-header.jpg?
w=300" alt="snow farm" width="696" height="290" />

</a>

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 '?'.

share|improve this answer

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.