WordPress Gallery Shortcode: Add a Simple Image Gallery to a Post or Page
When I was researching the upcoming features for WordPress 2.9, I came across the following: “Add support for ‘include’ and ‘exclude’ to (Gallery Shortcode)”
I didn’t know what the gallery shortcode was all about so I looked into it and was pleasently surprised to discover a built-in WordPress feature that allows you to display a simple image gallery on a post or page.
The gallery shortcode will display all of the images that you have uploaded to that post or page as thumbnails. Here’s how you do that.
- Upload an image using the upload/insert button for the post or page where you want the images to display.
- Save the upload but don’t insert it into your post or page.
- Do this for each image that you want to display.
- Add
[gallery]
into your post or page where you want the gallery to be displayed.
The gallery will look like the following:
These are all photos of my favorite soccer goalie, Iker Casillas, who plays for Real Madrid. He has nothing to do with this post but I needed images for this article and he is one of my top ten celebrity crushes. ;-)
The gallery shortcode has a number of options that can be added to it. Some of them are:
- columns – You can specify the number of columns for the image display
[gallery columns="3"]
- id – This will display images attached to a specific post. For example, the gallery above displays the images for this post but by using the post id number I could display the images from a different post in this one.
[gallery id="292"]
- size – will set the size of the images. The default is thumbnail but you can also use the medium and large images.
[gallery size="medium"]
Obviously, this is not as full features as a gallery plugin like NextGen Gallery but for a quick and easy gallery on a post or page this shortcode works great.
I just can’t believe that I was completely clueless about it until recently.
If you want to read more about the gallery shortcode, there is information in the codex.
photo credit: voteprime
Related Posts:


















November 18, 2009 at 3:33 am
Great tip Kim. Can’t wait till they release WordPress 2.9 stable version to try this out. One question though. How do you combine [gallery size="medium"] and [gallery columns="3"]
November 18, 2009 at 10:49 am
Hi Yohan – Sorry if I was unclear. The shortcode works now – they are just adding some features to it in 2.9. You can use it now.
You can just combine the options gallery columns=”2″ size=”medium” enclosed in the brackets.
November 18, 2009 at 4:31 am
Ohhhhhh… I didn’t know that either.
Of course I only found out last week that you can edit images inside the WordPress editor. I always switched to code view to add a class/resize/whatever.
Dave´s last blog ..Add the WordPress search function to your Thesis header
November 18, 2009 at 10:53 am
Hi Dave – Oh good. I wasn’t the only one. It’s amazing how I keep learning new things.
I didn’t know there was an editor for a long time either – I guess I never needed to use it.
November 18, 2009 at 4:50 am
Oh this is an awesome tip/discovery! We always have so many of Pete’s images and I’ve wanted to do this, but felt it had to be done singly and subject to WYSIWYG weirdness. Thank you, Kim; this is so very helpful.
Betsy Wuebker´s last blog ..Down to Sleep: The November Garden
November 18, 2009 at 10:53 am
Hi Betsy – Great! I’m so glad it will help. I was surprised to discover it and it’s easy to use.
November 18, 2009 at 9:04 am
Awesome!
Love the Iker gallery.
November 18, 2009 at 10:54 am
Hi Jim – I should use examples that include Iker in all of my posts ;-)
November 18, 2009 at 9:12 am
Fantastic tip..thanks Kim. Have I told you that you are “the real deal” before? If not, then there it is. Thanks!
Rick Castellini´s last blog ..NEW Live Radio & Web Show today at NOON – Mountain Time!
November 18, 2009 at 10:54 am
Hi Rick – Thanks! This was a good find :-)
November 18, 2009 at 1:43 pm
Cool – thanks.
Yup, I remember your top ten celebrity crushes post. :)
vered | blogger for hire´s last blog ..Genetic Testing for Children: Would You Do It?
November 18, 2009 at 3:31 pm
Hi Vered – Thanks :-) I still like Iker ;-)
November 19, 2009 at 9:56 pm
I’d like to hear some usage stats, how much the system slows with the galleries and all..
Dennis Edell´s last blog ..IS An Advertising Page Really A Good Idea? An Interesting Opposing View…
November 20, 2009 at 7:32 am
Hi Dennis – I’m not sure. But a lot of plugins use shortcodes so I can’t see how this would slow things down more than the plugins do.
November 20, 2009 at 6:56 pm
I’m just sayin, one of the first things drummed into your head as a newbie is, watch them pictures/images, it will slooooooooooow things down. lol
For that I always ask…
Dennis Edell´s last blog ..IS An Advertising Page Really A Good Idea? An Interesting Opposing View…