logo

$8
Make images link to medium or large size — not full

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 Link URL 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!

Hein Tore Tønnesen | 06/24/10 at 4:37pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    06/24/10
    6:02pm
    Oleg Butuzov says:

    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

    attachment image View Attachment

    Previous versions of this answer: 06/24/10 at 4:58pm | 06/24/10 at 5:02pm | 06/24/10 at 5:14pm | 06/24/10 at 5:14pm | 06/24/10 at 5:22pm

  • avatar
    Last edited:
    06/24/10
    4:44pm
    Rashad Aliyev says:

    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 largelink, find it at your CSS and replase how you want.

    If you need more help please contact with me.

  • avatar
    Last edited:
    06/24/10
    4:46pm
    Chris Lee says:

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

    http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/

    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?

This question has expired.





Current status of this question: Completed