Português do Brasil •
(Add your language)
The Gallery feature allows you to add one or more image galleries to your posts and pages. Since WordPress 2.5 and up until 3.5, the gallery shortcode was commonly used in its most basic form:
Following 3.5, gallery shortcodes now include the image IDs by default. Like this:
It's important to note that this style of gallery shortcode is not new to 3.5, previously we could use the include attribute. However it is much easier to generate and manage with the new Media Workflow introduced in 3.5.
Specifying IDs in your shortcode allows you to include images in your gallery that aren't necessarily "attached" to your post — that is to say, not uploaded from within your post or page. This flexibility allows you to create and embed any number of galleries containing any number of images!
Note: If you choose to just use the "barebones" version of the [gallery] shortcode in your post or page, only images that are "attached" to that post or page will be displayed.
There are several options that may be specified using this syntax:
[gallery option1="value1" option2="value2"]
You can also print a gallery directly in a template like so:
<?php echo do_shortcode('[gallery option1="value1"]'); ?>
This works too:
$gallery_shortcode = '[gallery id="' . intval( $post->post_parent ) . '"]';
print apply_filters( 'the_content', $gallery_shortcode );
The following basic options are supported:
- specify how to sort the display thumbnails. The default is "menu_order". Options:
- menu_order - you can reorder the images in the Gallery tab of the Add Media pop-up
- title - order by the title of the image in the Media Library
- post_date - sort by date/time
- rand - order randomly
- specify the sort order used to display thumbnails. ASC or DESC. For example, to sort by ID, DESC:
[gallery order="DESC" orderby="ID"]
- specify the number of columns. The gallery will include a break tag at the end of each row, and calculate the column width as appropriate. The default value is 3. If columns is set to 0, no row breaks will be included. For example, to display a 4 column gallery:
- specify the post ID. The gallery will display images which are attached to that post. The default behavior, if no ID is specified, is to display images attached to the current post. For example, to display images attached to post 123:
- specify the image size to use for the thumbnail display. Valid values include "thumbnail", "medium", "large", "full" and any other additional image size that was registered with add_image_size(). The default value is "thumbnail". The size of the images for "thumbnail", "medium" and "large" can be configured in WordPress admin panel under Settings > Media. For example, to display a gallery of medium sized images:
Some advanced options are available:
- the name of the XHTML tag used to enclose each item in the gallery. The default is "dl".
- the name of the XHTML tag used to enclose each thumbnail icon in the gallery. The default is "dt".
- the name of the XHTML tag used to enclose each caption. The default is "dd". For example, to change the gallery markup to use div, span and p tags:
[gallery itemtag="div" icontag="span" captiontag="p"]
- you can set it to "file" so each image will link to the image file. The default value links to the attachment's permalink.
- comma separated attachment IDs to show only the images from these attachments.
- comma separated attachment IDs excludes the images from these attachments. Please note that include and exclude cannot be used together.
The gallery shortcode is located in wp-includes/media.php.