Skip to main content

[bec_unit_gallery]

Returns the unit’s canonical gallery as a JSON string built from bec_core_gallery (WordPress attachment IDs imported during sync). Each item includes resolved image metadata for a chosen size.

This shortcode is aimed at custom front-end code (JavaScript sliders, React/Vue blocks, etc.). It does not render HTML markup itself and does not enqueue Booking Engine public CSS/JS.


Where to put it

Hidden in a template, inside a wrapper your theme reads with JavaScript, or anywhere you parse JSON on the client.


Attributes

AttributeDefaultMeaning
unit_id0Units post ID; 0 uses the current bec_unit in the loop.
limit6Maximum images after offset. Use 0 for the full gallery.
offset0Skip the first N attachment IDs (gallery order from meta).
sizelargeWordPress image size slug passed to wp_get_attachment_image_src() (e.g. medium, full).
default[]JSON fallback when the unit has no gallery — must be valid JSON (default empty array).

JSON shape

Each element is an object:

KeyTypeMeaning
idintAttachment post ID
urlstringImage URL for size
altstringAlt text from the attachment
widthintWidth in pixels (0 if unknown)
heightintHeight in pixels (0 if unknown)

The shortcode outputs HTML-escaped JSON (safe to place in a <script type="application/json"> block or a data-* attribute if you decode on the client).

Example output (illustrative):

[{"id":101,"url":"https://example.com/wp-content/uploads/photo.jpg","alt":"Living room","width":1024,"height":768}]

Examples

First six images (default):

[bec_unit_gallery]

Full gallery, medium size:

[bec_unit_gallery limit="0" size="medium"]

Second page of thumbnails (skip 6, take 6):

[bec_unit_gallery offset="6" limit="6"]

Specific unit with custom empty fallback:

[bec_unit_gallery unit_id="123" default="[]"]

Developer hooks

FilterPurpose
bec_unit_gallery_attachment_idsAdjust attachment ID list before URL resolution ($ids, $unitId, $context).
bec_unit_gallery_itemsAdjust resolved item objects ($items, $unitId, $context).
bec_unit_gallery_jsonAdjust final JSON string ($json, $postId, $atts).

Elementor alternative

For Elementor Gallery or Media Carousel widgets, use the Unit gallery dynamic tag instead — see Elementor — Unit gallery.