Word Press Gallery Link to Large Image Instead of Original

I created a simple gallery on a page showing pictures of our new office.  I wanted the pictures to link to the large size WordPress image instead of the original image.  My original images where taken with a Canon Rebel T2i so that where over 5mgs each.  So, the default WordPress functionality to link to the original image wasn’t very useful.  After fighting with things for a while, I finally found the below code courtesy of Jeff Lundberg.

add_filter(‘attachment_fields_to_edit’, ‘large_attachment_fields_to_edit’, 0, 2);
function large_attachment_fields_to_edit($fields, $post){
if (substr($post->post_mime_type,0,5) == ‘image’){
$html = “<input type=’text’ class=’text urlfield’ name=’attachments[$post->ID][url]‘ value=’” . esc_attr(array_shift( wp_get_attachment_image_src($post->ID, ‘large’, false) )) . “‘ /><br />
<button type=’button’ class=’button urlnone’ title=”>” . __(‘None’) . “</button>
<button type=’button’ class=’button urlfile’ title=’”.esc_attr(array_shift( wp_get_attachment_image_src($post->ID, ‘large’, false) )).”‘>Large File URL</button>
<button type=’button’ class=’button urlfile’ title=’” . esc_attr(wp_get_attachment_url($post->ID)) . “‘>” . __(‘Original File URL’) . “</button>
<button type=’button’ class=’button urlpost’ title=’” . esc_attr(get_attachment_link($post->ID)) . “‘>” . __(‘Post URL’) . “</button>
$fields['url']['html'] = $html;
return $fields;

View other articles in: Code