Fix for image attachment problems in Twenty Ten 1.1 wordpress theme

I noticed after uploading any image 900 pixels width and viewing the picture on the attachment page, then this image was cropped and was always 198 pixels in height. It was strange, then I find out what was going on in the theme code. I found in the file attachment.php code which is responsible for displaying an image for attachment page:

$attachment_size = apply_filters( 'twentyten_attachment_size', 900 );
echo wp_get_attachment_image( $post->ID, array( $attachment_size, 9999 ) ); // filterable image width with, essentially, no limit for image height.

This code show 900 pixels width images, but 900 pixels width image can be the original image or image for a header (or featured), and therefore code will use the picture for the header. Twenty Ten 1.1 theme adds new image size 940×198 pixels, but sometimes image not big enough so it cut to 900×198, 800×198 etc. That is why those images are displayed.

To solve this problem, I replaced 2 lines code to new:

echo wp_get_attachment_image( $post->ID, 'large' );

Now attachment page always display large image, if there is no large image (too small to crop) then it will display original image.

Then specifically for Twenty Ten 1.1 theme  I changed media settings in administration. Thumbnail size is good 150×150 so I don’t change it, theme use thumbnail in galleries. Medium size I changed to 640 max width and 9999 max height, because Twenty Ten 1.1 theme post max width 640 so this image size perfect for inserting images in posts. Next large size I changed to max width 900 and 9999 max height, because this image will be in attachment page.

4 thoughts on “Fix for image attachment problems in Twenty Ten 1.1 wordpress theme”

  1. Thank you, thank you, thank you! It’s so annoying that Twentyten puts the full size image on the attachment page and then relies on the browser to scale it. I’ve wanted to change this so that the ‘large’ version is displayed instead, but I wasn’t sure how. Surprisingly, I couldn’t find this information anywhere in the WP forums.

    Thank you so much, this is exactly what I needed.

  2. Thanks! In 2010 v1.4 I found the code in loop-attachment.php where there are three lines to replace, not two. Just search for “get_attachment_image” and there it is. Otherwise the fix works just fine!

Leave a Reply

Your email address will not be published.