Almost a year ago I wrote about how a simple gallery could be added to a post or page using the WordPress Gallery Shortcode. At the time I found out about it because include and exclude were going to be added to later releases. It is now part of the shortcode.
Last week I used the gallery shortcode for the Halloweeen themes post but I didn’t want to use all of the images in the gallery – the photo of the cupcakes is in the gallery associated with that post but I wanted to exclude it because it isn’t an image of a theme.
Using include or exclude looks like the following
[gallery exclude=”21,32,43″]
You can not use include and exclude in the same shortcode – it has to be one of the other. The numbers being exclude are the attachment ID’s for each image that you don’t want to display. When I looked in the gallery, however, for that post I didn’t see any attachment ID’s.
It turns out that you have to get the attachment ID from the media library.
- Go to Media > Library
- Click on the title of the image that you want to exclude.
- The attachment ID will be in the URL in your browser’s address bar. For example, the image include in this post has the URL
https://www.kimwoodbridge.com/dev/wp-admin/media.php?attachment_id=9633&action=edit The attachment id is 9633.
I typically add images through upload/insert when writing a post and not through the media library. It would be helpful if the attachment id was included in both locations. At any rate, this feature makes the simple image gallery included with WordPress a lot more useful.
photo credit: Schristia
Interesting article…I didn`t know I can do that with wordpress.Thank you!
Hi Claudia – I didn’t know anything about the gallery until I wrote the first
article – I came across is accidentally.
“I typically add images through upload/insert when writing a post and not through the media library.” Same here.
Hi Vered – Yeah – so getting the attachment ID requires an extra step.
Thank you so much! I’ve been wondering if something like this were going to come along soon! :)
Hi – It’s been around for a little while now but I wasn’t really paying attention – it’s a useful addition.
Thanks you are a life saver I was going nuts trying to find that pesky attachment id.
Hi Jerry – It’s really hidden, isn’t it?