Full Size Image in WordPress Default Gallery

March 5, 2010 by nichive · 1 Comment
Filed under: How-To 

WordPress Gallery 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 gallery 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 theme’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).

Share and Enjoy:
  • Google Bookmarks
  • Digg
  • StumbleUpon
  • Technorati
  • Facebook
  • Reddit
  • Tumblr
  • Twitter

Related posts:

  1. WordPress Maintenace Notice
  2. How to Install WordPress Plugins
  3. Facebook Emoticon for WordPress

Comments

One Response to “Full Size Image in WordPress Default Gallery”
  1. Jason says:

    Excellent. Thanks!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


:smile: :tongue: :unsure: :squint: :glasses: :gasp: :wink: :kiki: more »