Skip to content

Shortcode ​

[shaped_gallery id="42"] — the one tag, what it accepts, and how to use it from PHP.

The tag ​

[shaped_gallery id="42"]

One attribute, id: the post id of a reusable gallery. That's the whole surface.

You never need to write it by hand — copy it from the gallery's Gallery Info panel, its Post tab, or the Shortcode column of Shaped Gallery → Saved Galleries.

From PHP ​

php
echo do_shortcode( '[shaped_gallery id="42"]' );

In a template, that's all there is to it. The output is already escaped.

What it renders ​

The shortcode reads the gallery's stored block content and runs it through the block's own renderer. It is not a second implementation.

That's the pillar the whole placement story rests on: a gallery placed as a block, as a shortcode, or through a page-builder element produces byte-identical markup, CSS and JavaScript. There's no "shortcode version" of a feature to fall behind.

Guards ​

The shortcode applies every rule the block does, plus a few of its own:

SituationResult
The id doesn't exist, or isn't a galleryEmpty output.
The gallery is in the trashEmpty output.
The gallery is a draftRendered only for users who can edit it.
A gallery embeds itselfThe recursion is caught; empty output.
The gallery is PrivateEmpty output for anyone without permission.
The gallery is Password-protectedThe password form, then the gallery.
The license isn't activeAdministrators get a notice; visitors get empty output.

Every one of those returns an empty string, never an error message on your page.

Filtering the output ​

php
add_filter(
    'shaped_gallery_shortcode_output',
    function ( $html, $gallery_id ) {
        return '<div class="my-wrapper">' . $html . '</div>';
    },
    10,
    2
);

Building the tag in code ​

Don't spell the tag out in your own code. The plugin has one builder for it, so the format can't drift:

php
use ShapedPlugin\ShapedGallery\Frontend\Frontend;

$shortcode = Frontend::shortcode_for( 42 );
// [shaped_gallery id="42"]

The string depends on nothing but the post id, which is what makes it permanent across edits.

Reusable galleries are posts of the shaped_gallery type:

php
$galleries = get_posts(
    array(
        'post_type'      => 'shaped_gallery',
        'post_status'    => 'publish',
        'posts_per_page' => -1,
    )
);

foreach ( $galleries as $gallery ) {
    echo esc_html( $gallery->post_title ) . ': ' . $gallery->ID . "\n";
}

Two derived meta keys are maintained for you on every save — for the native editor, the REST route, an import and a duplicate alike:

Meta keyHolds
_shaped_gallery_layoutThe gallery's current layout id.
_shaped_gallery_item_countHow many items it holds.

Both are recomputed from the saved content, never written by a caller. Don't write to them — you'd be overwritten on the next save, and two derivations is how a stale layout column happens.

Things worth knowing ​

The tag never changes. [shaped_gallery] is fixed — stored pages depend on it, and both the free and Pro builds use the same one.

Galleries embedded in a page have no shortcode. Only saved galleries do. That's the difference between the two placement models. More →

Editing a gallery updates every placement. Pages hold a reference, so there's no sync step — and deleting a gallery blanks it everywhere.

Where to go next ​