Made in Europe, buy from Europe.

Black Friday

65% off Annual plans

25% off Lifetime · 10 per week

Ends December 2

Get the deal →

9 min read

WordPress Gallery Shortcode: Add a Gallery Anywhere

WordPress gallery shortcode explained: all 12 built-in attributes, where to copy a Modula gallery’s shortcode, and how to add it to any page, post or sidebar.

What is a gallery shortcode and how do you create one in WordPress?

A WordPress gallery shortcode is one line in square brackets, like [gallery] or [modula id="89"], that WordPress swaps for a whole gallery when the page loads. You type a dozen characters. Your visitors see 40 photos in a tidy grid.

Good to know

Quick answer: open your gallery in Modula, click Embed at the top right and copy the Shortcode. Edit your page, add a Shortcode block (type /shortcode), paste and publish. Or skip the copying: add the Modula Gallery block and pick your gallery from the list.

What is a gallery shortcode?

A gallery shortcode is a placeholder tag that WordPress replaces with a gallery. WordPress or a plugin registers the tag, and wherever it appears, WordPress prints what it stands for.

With a gallery plugin, the nice part is that the shortcode is a bookmark, not a copy. The gallery lives in one place, so when you swap a photo, every page that uses it updates. No hunting through ten pages to replace one image.

A Shortcode block holding a Modula gallery shortcode in the editor, and the six-clip video gallery it shows on the published page.

[gallery] is one of WordPress’s built-in shortcodes, next to [audio], [video], [playlist] and [caption]. Plugins add their own, like Modula’s [modula].

To add a shortcode in WordPress, paste it almost anywhere:

  • Block editor: a Shortcode block. Type /shortcode on an empty line.
  • Classic editor: on its own line. The Classic Editor plugin has 8,000,000+ active installs (wordpress.org, October 2026), one big reason shortcodes haven’t gone away.
  • Widgets: a Shortcode block, or a Text widget with classic widgets.
  • Page builders: the builder’s shortcode or text element.
  • Theme files: <?php echo do_shortcode( '[gallery]' ); ?>

How to use the WordPress gallery shortcode

To use the WordPress gallery shortcode, type [gallery] into a post: WordPress shows every image uploaded to that post as small square thumbnails, in three columns on a classic theme.

Block themes skip WordPress’s default gallery styles, so there the thumbnails can stack one per row unless the theme styles them.

Add attributes (also called shortcode parameters) to pick the images and change the look. The shortcode dates back to WordPress 2.5 and takes 12 of them:

AttributeWhat it doesDefault
idsImages to show, by ID, in that orderImages attached to the post
columnsNumber of columns3
sizeAny image size: thumbnail, medium, large, fullthumbnail
linkWhat a click opens: the image file, or noneAttachment page
orderASC or DESCASC
orderbymenu_order, title, post_date, rand or IDmenu_order ID
idUse another post’s attached imagesCurrent post
includeOnly these image IDsNone
excludeLeave these image IDs outNone
itemtagTag around each itemfigure (HTML5 themes), else dl
icontagTag around each imagediv, else dt
captiontagTag around each captionfigcaption, else dd

Say you’re a potter with 12 product shots. Your shop page needs four of them, a bit bigger, and each one should open the full photo on click:

[gallery ids="12,15,18,21" columns="2" size="medium" link="file"]

Want a fresh order on every visit? Add orderby="rand".

To find an image’s ID, go to Media → Library and click the image. The number after item= in the address bar is the ID.

Good to know

Heads-up: paste [gallery ids="…"] straight into the block editor and WordPress turns it into a Gallery block. To keep it a shortcode, add a Shortcode block first and paste inside it.

A Shortcode block in the WordPress editor holding a gallery shortcode for images 12, 15, 18 and 21, in two columns at medium size, linked to the file.

Before you rely on the built-in shortcode

  • The default size is tiny. WordPress’s thumbnail is a 150 × 150 px square crop out of the box. That’s why a bare [gallery] looks like a contact sheet.
  • Attachment pages may be off. These single-image pages are off on sites installed on WordPress 6.4 or later, so the default link goes to the image file.
  • The image list lives in each post. Add a photo, and you edit every shortcode that should show it.
  • Columns are the only layout. No masonry, no filters, no lightbox (the full-size photo pop-up) of its own. If your posts are full of [gallery] shortcodes, you can migrate them to Modula.

For developers

Building a theme? These are the hooks you’ll reach for:

  • post_gallery: return non-empty HTML and it replaces the gallery output.
  • use_default_gallery_style / gallery_style: drop or rewrite the inline CSS (already off on HTML5 themes).
  • get_post_gallery() / get_post_gallery_images(): read a post’s gallery without rendering it.
add_filter( 'post_gallery', function ( $output, $attr ) {
    return my_gallery_markup( $attr ); // return '' to keep the default
}, 10, 2 );

The full reference is on developer.wordpress.org.

Get the shortcode of a Modula gallery

Every Modula gallery has its own shortcode, [modula id="89"], where 89 is the gallery’s ID. We make Modula, so that’s the one we’ll show. The shortcode works in the free version, which has 160,000+ active installs.

No gallery yet? Go to Modula → Content, click + New gallery, add your photos and pick one of 16 gallery types (8 are free). When you’re done, click Save in the top bar (or press Cmd/Ctrl+S). See the full walkthrough.

Then copy the shortcode from either place:

  • The gallery editor: click Embed at the top right. The “Embed this gallery” panel has a copy button next to Shortcode.
  • Modula → Content: the Shortcode column shows each gallery’s code, and the row’s Copy shortcode action copies it.
The Embed this gallery panel in the Modula editor with copy buttons for the shortcode, the PHP line and the Modula Link shortcode

The panel also has a PHP (theme templates) line for theme files. With Modula Pro, a Modula Link row gives you a text link that opens the whole gallery in a lightbox.

That row shows when Advanced Shortcodes is on, though the shortcode itself works on any Pro plan (see Modula Link).

Before you leave, check that the status next to the title says Published. Your visitors won’t see a draft gallery, even with a perfect shortcode.

Good to know

[modula] reads only id and align. The settings live in the gallery, so columns="4" changes nothing.

Every Modula shortcode at a glance

ShortcodeWhat it showsPlan
[modula id="89"]The galleryFree
[modula-link id="89"]Click here[/modula-link]A link that opens the gallery in a lightboxAny Pro plan
[modula-album id="120"]An albumTrio and up
[[modula_all_galleries]]All galleries, or one picked by the addressTrio and up
[modula-download id="89"]Download Gallery[/modula-download]A download buttonBusiness

Add a Modula gallery to a page or post

The Modula Gallery block adds a gallery to any page or post in the block editor, with nothing to copy. Everywhere else, paste the [modula] shortcode.

With the Modula Gallery block

  1. Click + and search for Modula Gallery, or type /modula on an empty line.
  2. Click Display An Existing Gallery.
  3. Type in Search for a gallery… and pick yours. The block shows a preview.
  4. Preview the page, then publish.

The block outputs exactly the same gallery as the shortcode, because it runs [modula] for you. To change the gallery later, click Edit gallery (the pencil) in the block toolbar. It opens the gallery editor in a new tab.

The Modula Gallery block in the WordPress block editor with the Display An Existing Gallery button

With the Shortcode block or the classic editor

Add a Shortcode block and paste. In the classic editor, paste the shortcode on its own line, so WordPress doesn’t wrap it in a paragraph with your text.

As a sidebar or footer gallery widget

Add the Modula Gallery block or a Shortcode block in Appearance → Widgets. With the Classic Widgets plugin (2,000,000+ active installs on wordpress.org), use the Modula Gallery widget.

Keep it small. Six photos of a café’s weekly specials work in a narrow column. Sixty wedding shots don’t.

In page builders

The free plugin has its own element for the big three:

  • Elementor: the Modula widget (how-to).
  • Divi: the Modula Gallery module (how-to).
  • Beaver Builder: the Modula Gallery module (how-to).

Other builders, like WPBakery, take the shortcode in their text or shortcode element. The guide to inserting galleries covers a few more.

In theme files and block themes

On a classic theme, paste the Embed panel’s PHP line into a template, say under the homepage header. Use a child theme so updates don’t wipe it.

Block themes build their templates from blocks, so there’s no PHP to paste into. Open Appearance → Editor, open the template and add the Modula Gallery block. Remember that a template change shows on every page using that template.

Show multiple galleries on one page

A single WordPress page can show as many galleries as you like; there’s no cap. Create each gallery first (you’ll need at least two), then add one block or shortcode per gallery with a heading between them. Each keeps its own layout and lightbox.

Picture a wedding photographer’s page for one couple:

  • Ceremony: a Masonry gallery that keeps every photo’s shape.
  • Reception: a Justified grid with neat rows of party shots.
  • Portraits: a Polaroid gallery for the couple’s favorites.

All three layouts are free.

A few tips for gallery-heavy pages:

  • Name galleries clearly. “June wedding: ceremony” beats “Gallery 3” when you’re picking from a search list.
  • Try one gallery with filters. Visitors click Ceremony, Reception or Portraits above a single gallery. Filters come with Starter and up; see filterable galleries.
  • Use an album for long pages. It shows one cover per gallery, and a click opens it. Albums come with Trio and up; see Modula Albums.

One page for all your galleries

With Advanced Shortcodes (Trio and up), one page can show any gallery. Go to Modula → Settings → Galleries, copy [[modula_all_galleries]] from the Page with all galleries card and put it on a page like /galleries/.

Modula Settings, Galleries: the Page with all galleries card with the modula_all_galleries shortcode, a Copy button and the Link parameter field

The page lists every published gallery. Add ?gallery_id=89 to the address and it shows just that one, which is handy for menu links. More in Advanced Shortcodes.

Use one gallery on several pages

One Modula gallery can appear on any number of pages: drop its shortcode or block wherever you need it. Edit the gallery once, keep styling it after it’s live, and every page shows the change.

Want Masonry on the homepage but Polaroid on the about page? Use the Duplicate action on the gallery’s row in Modula → Content, then change the copy. To reuse just the settings on new galleries, save them as a preset (Presets, Business plan).

Build it once, drop it anywhere.

Frequently asked questions

WordPress prints a shortcode as text for one of three reasons. It’s in a Code block, which escapes square brackets on purpose. It’s wrapped in an extra pair of square brackets, which tells WordPress to print it as an example. Or the plugin that owns it is deactivated.

The fix: move it to a Shortcode block, remove the extra brackets and check your plugins.

Modula found no gallery with images behind the shortcode. The ID is missing, belongs to a page or post, or points to an empty gallery.

Copy the shortcode again from the Embed panel, or add images to the gallery.

You’re logged in, and Modula shows draft and private galleries to logged-in users who can read them. Visitors get “This gallery is not published.” instead. A gallery in the trash shows the same message.

Set the gallery to Published, then test in a private window. A scheduled gallery stays hidden until its date.

A blank space means the shortcode points nowhere or a script is held back. Curly quotes from a word processor (id=”89”) and a permanently deleted gallery’s ID print nothing, not even an error. Copy the shortcode again from the Embed panel.

If the code is right, exclude Modula’s scripts from your optimization plugin’s delay and combine settings, then clear your page and CDN caches.

No: [modula] only takes id and align, so columns="4" is ignored. The columns, layout and lightbox live in the gallery. Change them in the gallery editor, or duplicate the gallery for a different look.

A gallery’s ID is the number in its shortcode: 89 in [modula id="89"]. You’ll find it in the Shortcode column of Modula → Content and in the gallery’s Embed panel. More in locate your gallery ID.

No: the shortcode, the block, the widget and the Elementor, Divi and Beaver Builder elements are all free. Modula Link, albums, the all-galleries page and download buttons need a paid plan.

Make your next gallery
the one people remember.