WP Social Media Gallery Shortcode Reference
The WP Social Media Gallery shortcode embeds a saved gallery into any post, page, or widget area. The registered tag is [wp_social_media_gallery] and it accepts three attributes: id, return, and attributes. Layout, columns, and lightbox are configured per gallery in the builder, not as shortcode parameters.
Shortcode Syntax
The shortcode is registered as wp_social_media_gallery. It renders a gallery by ID inside a wrapper div. WordPress executes the shortcode in post content, page content, widget text, and any area that processes shortcodes.
Basic syntax:
- Minimal:
[wp_social_media_gallery id="1"] - With extra attributes:
[wp_social_media_gallery id="1" attributes="data-theme=dark"] - Return data:
[wp_social_media_gallery id="1" return="array"]
The id attribute is the only required parameter. If you omit it, administrators see an error card in the front-end output; all other visitors see nothing.
Attributes
The shortcode accepts exactly three attributes, defined in includes/class-gallery-preview.php. Do not use layout, columns, or lightbox — these are per-gallery builder settings, not shortcode parameters.
- id: The gallery ID. Integer. Default: 0. Required in practice. Find the ID in the Gallery Builder list or in the browser URL when editing a gallery.
- return: Output format. Accepts
string(default) orarray. Usearrayto receive the gallery data object instead of rendered markup. - attributes: Extra HTML attributes to add to the wrapper div. Sanitized with
sanitize_text_field. Default: empty string. Use this to add a CSS class or data attribute.
The return attribute is useful when you need the raw gallery data in a template. The attributes attribute is useful for targeting the wrapper with custom CSS or JavaScript.
Usage Examples
Paste the shortcode into any post, page, or widget area that processes shortcodes.
- Basic embed:
[wp_social_media_gallery id="1"]renders gallery 1 with its saved settings. - Custom wrapper attributes:
[wp_social_media_gallery id="1" attributes="data-theme=hero-gallery"]addsdata-theme="hero-gallery"to the wrapper div. - Return data:
[wp_social_media_gallery id="1" return="array"]returns the gallery config array. Use this inside a custom PHP template withdo_shortcode(). - In a widget: Add a Text widget, switch to the Text editor (not Visual), and paste the shortcode. The Text widget processes shortcodes by default.
The Gutenberg block does the same thing without typing the shortcode. The block stores the gallery ID in post content and renders it on the front end. See the guide to using the WordPress gallery block for the block workflow.
Output Markup
When return="string" (the default), the shortcode outputs a single wrapper div. The div carries the gallery ID, a data attribute pointing to the per-instance config global, and the gallery type as a CSS class.
- Wrapper ID:
ccpwpsmg-gallery-{id} - Data ID:
CCPWPSMG_{id} - CSS class:
ccpwpsmg-{type}plusccpwpsmg-top-level-wrapper
The config is delivered through window.CCPWPSMG_{id}, injected as an inline script before the gallery bundle loads. Sensitive keys such as access_token, api_key, and client_secret are stripped from the front-end config.
Tips
Use the shortcode when you need more control than the block provides, or when you are building a custom template.
- Always escape shortcode brackets in documentation:
[wp_social_media_gallery id="1"]. Unescaped brackets will execute the shortcode inside a code block. - Change layout, columns, spacing, and lightbox settings in the Gallery Builder, not in the shortcode.
- The shortcode returns an empty string for non-administrators when the
idis missing or invalid. Check the gallery status if the shortcode renders nothing for visitors. - If you use
return="array", process the result in PHP before echoing it. The raw array is not safe for direct output.
For programmatic access, the plugin also exposes a REST API at ccpwpsmg/v1. See the REST API overview for endpoints and authentication.