The other day, I was playing around with the WordPress [
] shortcode, and came across the need to exclude an image that was attached to the page. The image I needed to exclude was kind of like a featured image, and I didn’t want it to appear again in the gallery itself. So, I searched for information about excluding images from the WordPress [
] shortcode, and came across the related WordPress Codex article.
While reading that article, I noticed a handful of features I’d never known about in that particular shortcode. After all, I always basically assumed that the options WordPress gives you when inserting a gallery were probably the only options that were available.
Turns out I was wrong. In addition to the “Order By”, “Columns” and “Links” options that the WordPress interface offers, the [
] shortcode accepts the following extra options:
- id – In case you want to show the gallery from a page other than the one you’re currently editing. By default, WordPress simply shows the images that are attached to the current page, but you can override that by providing another page’s ID.
- size – Choose from any of the defined (named) image sizes in WordPress. By default, WordPress displays the “thumb” size (which might not be ideal, since that is usually a cropped image).
- itemtag – The HTML element that’s used to wrap each item (which includes the image and the caption together) in the gallery. By default, WordPress uses a <dl> tag, making each gallery item a separate definition list.
- icontag – The HTML element that’s used to wrap each image inside of the gallery. By default, WordPress makes each image a <dt>
- captiontag – The HTML element used to wrap each caption in the gallery. By default, WordPress uses <dd>
- include/exclude – You can provide a comma-separated list of attachment IDs that WordPress should either include explicitly (leaving all others out) or exclude (causing WordPress to use all other items that are attached to the page) in the gallery.