Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Make images link to medium or large size — not full WordPress

  • SOLVED

Alright, this has been bugging me for quite a while, and I've yet to find a decent answer that doesn't involves tearing up WordPress' core files.

How do I make images that are inserted into a post link to the medium or large version, and not the full size?

I see two possible solutions — but I'm not clever enough to hack together a plugin.

1) Create a new button under <em>Link URL</em> in the Media/Gallery section that says "Large Size"
2) Filter the function that outputs images in posts to show the medium/large version instead of the full size

Other suggestions and solutions are of course just as welcome.

Thanks!

Answers (3)

2010-06-24

Oleg Butuzov answers:

insert this code to functions.php of your theme.

add_filter('attachment_fields_to_edit', 'medium_attachment_fields_to_edit', 0, 2);
function medium_attachment_fields_to_edit($fields, $post){

if (substr($post->post_mime_type,0,5) == 'image'){

$fields['url']['html'] = str_replace("<button type='button' class='button urlfile'", "<button type='button' class='button urlfile' title='".esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'medium', false) ))."'>Medium File URL</button>\n<button type='button' class='button urlfile'", $fields['url']['html']);

}

return $fields;
}


added screnshot


Oleg Butuzov comments:

tested on wp 3.0

2010-06-24

Rashad Aliyev answers:

You can made it via CSS file. Look at HTML codes and find your links CLASS, for example: <a href="www.evlenirik.biz" class="largelink">My site</a>

Our class is <strong>largelink</strong>, find it at your CSS and replase how you want.

If you need more help please contact with me.

2010-06-24

Chris Lee answers:

Not sure what your use is for this but you could just insert a post thumbnail for the post:

[[LINK href="http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/"]]http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/[[/LINK]]

The issue is if you need this to change from large to medium to small size this may be difficult.

Often times i have wordpress spit out both images and have jquery hide one or the other thumbnail based on the template. This could also allow you to (further down the line) to build something more complicated.

Does that help?