*** UPDATE: Unfortunately, this method no longer works with the new media uploader introduced in WordPress 3.5 ***
Usually when an image thumbnail is inserted into a post, I would like the thumbnail to link to the large version of the image, not the full-size version. Often the original full-size version is straight from a user’s high-megapixel camera and takes a while to load, while the large version has been automatically downsized by WordPress according to its media settings and works beautifully with a lightbox plugin or script.
WordPress automatically creates a large version of the image, but unfortunately it does not support linking to the large version very easily at all from the Add Media window.
Thanks to this code from SergeyBiryukov, I created a simple plugin that adds the option to link to either the Full Size Image or the Large Image from the Add Media window:
Much better!
You may install the following plugin on WordPress 3.4.2 or drop it directly into the mu-plugins directory of your multisite installation: add-link-to-large-image.php
Here’s the code:
[fancy_code_box]
function add_link_to_large_image( $form_fields, $post ) {
$file = wp_get_attachment_url( $post->ID );
$link = get_attachment_link( $post->ID );
$url_type = get_option( ‘image_default_link_type’ );
if ( empty( $url_type ) )
$url_type = get_user_setting( ‘urlbutton’, ‘post’ );
$url = ”;
if ( $url_type == ‘file’ )
$url = $file;
elseif ( $url_type == ‘post’ )
$url = $link;
if ( substr( $post->post_mime_type, 0, 5 ) == ‘image’ ) {
$large_image_array = wp_get_attachment_image_src( $post->ID, ‘large’ );
$file_large = $large_image_array[0];
$url = $file_large;
}
$form_fields[‘url’][‘html’] = ”
“;
if ( ! empty( $file_large ) )
$form_fields[‘url’][‘html’] .= ”
“;
$form_fields[‘url’][‘html’] .= ”
“;
return $form_fields;
}
add_filter( ‘attachment_fields_to_edit’, ‘add_link_to_large_image’, 10, 2 );
[/fancy_code_box]
How would this work with the new Media File management on WordPres 3.5.1 dropdown options?
I think they’ve ruined this new media uploader & manager to be honest, to even just set a featured image now we need to open the window twice :S
Any suggestions?
This is exactly what I need, but I am unsure of two things. First, will it work with wordpress 3.5.1 (probably upgraging to 3.8.1 soon)? Second, how do I install this? Couldn’t find it in plugins and am not quite to the point of installing manually.
Any help would be appreciated.
Thanks!
I’m sorry guys, but unfortunately this method no longer works with the new media uploader introduced in 3.5.