Docs
Gallery shortcodes by category
With enhanced media shortcodes on, WordPress's own [gallery] and [playlist] shortcodes can show the files in a category, from a month, or the latest few, instead of a fixed list.
Turn it on
Go to Settings → Media Library, tick Enhanced media shortcodes and save. Then check your galleries, since some themes and gallery plugins change the gallery shortcode too.
Examples
[gallery media_category="coffee-tea"]
[gallery media_category="5" limit="10" columns="4"]
[gallery media_category="landscapes,wildlife" year="2026" monthnum="6"]
[gallery media_category="landscapes+homepage"]
[playlist media_category="podcasts" limit="5"]
[playlist type="video" media_category="tutorials"]
Attributes
| Attribute | What it does |
|---|---|
media_category or any media taxonomy | Category IDs or slugs. Separate with commas for files in any of them, or with + for files in all of them. Several taxonomies together must all match. |
limit | How many files to show. All of them if left out. |
year and monthnum | Only files uploaded in that month. Use both together. |
type | image (the default for galleries), audio, video or pdf. |
id | Only files uploaded to that post or page. |
orderby, order | Sorting, as in WordPress. If left out, the order set in Settings → Media Library is used, including your custom drag-and-drop order. |
Everything else, such as columns, size and link, works as usual. Whether child categories are included follows the Include children setting.
If no files match, WordPress falls back to its normal behaviour and shows the files attached to the page, as a plain [gallery] would.
In the editor
In the classic editor's gallery settings, or the Shortcode block, you can build the gallery from a category instead of picking files one by one. The block editor's Gallery block stores a fixed list of images, so it isn't affected by these attributes.