• Background: I am trying to use WordPress to resize images uploaded by my users. They are not very savvy when it comes to sizing images before uploading. WP does a fantastic job of reducing the image sizes. My issue is that I would like to use any of the myriad of lightbox-type plugins that require a link to the original file to fire. Often the images that get uploaded are SO big that they consume the entire screen four times over when viewed in a lightbox-type environment. Some of the plugins will artificially re-size the images, but this is done on the fly and still requires a long download time.

    Problem: I would like to know if there is a way to make the “File URL” button or the “Link to Image” button (found when adding images to posts) function in a way that provides a link to the “medium” (or any other size) image instead of the original file. I would also like to do the same for the automatically generated image gallery in WP. That is, I’d like [gallery link="file"] to actually link the thumbnails to the “medium” sized images.

    I would like to avoid altering core files, but I am not totally against it if there aren’t any hooks that can be used instead.

    Any thoughts? Thanks!

Viewing 1 replies (of 1 total)
  • Came here wanting ot do the same thing.

    After a lot of googling, some fumbling at adapting other code snippets and some help from some much better coders, I can help you with the media library part. You can use this in your theme’s ‘funtions.php’ to filter out the ‘File URL’ button and replace it with a button that generates a link to a specified image size (medium in the example).

    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'] = preg_replace("/<button type='button' class='button urlfile' title='(.)*'>(.*)<\/button>/Ui",
    												"<button type='button' class='button urlfile' title='".esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'medium', false) ))."'>Medium Image</button>",
    												$fields['url']['html']);
    	}
    	return $fields;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Change “File URL” and “Link to Image” button functionality’ is closed to new replies.