Full Size Image in WordPress Default Gallery

March 5, 2010 by · 5 Comments
Filed under: How-To 

is indeed a handy tools to neatly insert your collection of pictures and order them easily in your post, without being bothered by performing manual arrangement (such as using tables, etc.) through the HTML editor. But there was this time when I feel annoyed because when one of the image in the was clicked, the loaded page didn’t show a full scaled image, instead it displayed a medium-size.

I then realized that this is something that related to ’s functionality, because there is no option to set the image size in the gallery setting.

The solution is by adding a specific template that handles the image attachment page. If you check your wp-content/themes folder, you will notice that those files that are found in there, are templates which WordPress uses to display the content of your blog (or the category, or the attachment).

By default, WordPress uses the single.php file as the template that handles all your image attachments. And this default is something that we should tinker with :smile:

Please remember, whenever you are going to to some changes on your theme’s file(s), make sure you back up all the original files. So incase your themes got screwed, you can easily switch back to the previous state.

This steps should be conducted NOT directly in your wp-admin theme editor, because we need to create a new file. So I suggest you use your hosting file manager or work in local drive before upload the file.

  1. Go to your theme’s folder (wp-content/themes/theme-name)
  2. Locate the single.php file.
  3. Duplicate the file (make a copy) and name the new file as image.php
  4. Inside the image.php file, you will find this code:
    <?php the_content(); ?>
  5. Replace that part with the following code:
    <?php if (wp_attachment_is_image($post->id)) {
    $att_image = wp_get_attachment_image_src( $post->id, "full-size");
    ?>
    <p class="attachment">
    <img src="<?php echo $att_image[0];?>" width="<?php echo $att_image[1];?>" height="<?php echo $att_image[2];?>" class="attachment-full-size" alt="<?php $post->post_excerpt; ?>" />
    </p>
    <?php } ?>
  6. Safe the file, and upload it to your theme’s folder

This approach will tell WordPress that to display an image attachment, the template image.php should be the one to be used. And since we set the image’s real width and height value in the template, then the image will be displayed in full size (instead of medium size, as in single.php).

Be Sociable, Share!

Related posts:

  1. WordPress Maintenace Notice
  2. Custom WordPress Maintenance Note
  3. Keep Your Themes Safe
  4. How to Install WordPress Plugins
  5. Facebook Emoticon for WordPress
  • http://www.polyartist.se/blog Jason

    Excellent. Thanks!

  • http://smok.zoxt.net Vladimir

    Thank you!
    Notice: it’s better to not replace the_content() with your code, just add code before the_content() because the_content() displays image’s description.

    • http://nichpakaich.com nichive

      Well, you provided a useful notice there.
      Didn’t give any thought about the image’s description, actually.

      Thanks for the notice.

  • http:AldebaranWebDesign.com Jill

    Wonderful article. I’d mention that if you’re using the Twenty Ten theme (new WordPress default), there’s a file for the attachments called loop-attachment.php and you can directly modify this file and not worry about it impacting the single pages because those are controlled by a different file. This separation of files in the new default theme is a big improvement I think.

    Inside this file, you can change one line and get full size display:

    echo wp_get_attachment_image( $post->ID, array( “full-size”, “full-size” ) );

    Would never have found this solution without your post, Thank you!!!!!!!
    Jill

  • http://teckzone.in Virendra Rajput

    Thanks ! tHAT REALLY HELPED ME