Lightbox: Developer Reference

6 min read

Updated May 20, 2026

Technical reference for developers working with the FotoGrids Lightbox — custom events, HTML trigger attributes, the data-fg-lb-* settings system, and the REST endpoint the info panel uses.

Audience: Developers building custom themes, rendering galleries outside WordPress, or extending Lightbox behavior with JavaScript.


Custom Events #

The Lightbox dispatches three custom events on the gallery wrapper element (the .fotogrids-gallery element that wraps the items). Listen at the gallery level to scope handlers to a specific gallery. Events also bubble, so document-level listeners work.

fotogrids:lightbox:open

Fired when the Lightbox opens on an item.

galleryEl.addEventListener( 'fotogrids:lightbox:open', ( e ) => {
    const { galleryEl, index, item } = e.detail;
} );
PropertyTypeDescription
galleryElElementThe gallery wrapper that was opened
indexnumberZero-based index of the item that was clicked
itemobjectItem data object (see Item Object below)

fotogrids:lightbox:navigate

Fired each time the visitor moves to a different item — by arrow, dot, keyboard, swipe, or thumbnail click.

galleryEl.addEventListener( 'fotogrids:lightbox:navigate', ( e ) => {
    const { galleryEl, index, item, direction } = e.detail;
} );
PropertyTypeDescription
galleryElElementThe gallery wrapper currently open
indexnumberZero-based index of the item now displayed
itemobjectItem data object for the new item
direction'next' | 'prev'Which direction the visitor navigated

fotogrids:lightbox:close

Fired when the Lightbox closes, before focus is returned to the trigger element.

galleryEl.addEventListener( 'fotogrids:lightbox:close', ( e ) => {
    const { galleryEl } = e.detail;
} );
PropertyTypeDescription
galleryElElementThe gallery wrapper that was open

Item Object

The item object passed in open and navigate events:

{
    triggerEl,   // Element  — the <a> with [data-fg-lightbox-trigger] that was clicked
    fullSrc,     // string   — URL of the full-size image/video (href of the trigger)
    thumbSrc,    // string   — URL of the thumbnail (src of the <img> inside the trigger)
    alt,         // string   — alt text of the thumbnail image
    caption,     // string   — value of data-fg-caption on the trigger
    title,       // string   — value of data-fg-title on the trigger
    id,          // string   — value of data-fg-item-id on the trigger (used for REST fetch)
}

HTML Trigger Attributes #

The Lightbox is initialised entirely from the DOM — no JavaScript configuration object is required.

On the gallery wrapper element

AttributeValueDescription
data-fg-click"lightbox"Marks this gallery as Lightbox-enabled. The Lightbox init script scans for this attribute and wires click handlers.

On each item’s <a> link

AttributeDescription
data-fg-lightbox-triggerPresent (no value needed) — marks this link as a Lightbox trigger.
hrefFull-size media URL — what the Lightbox actually displays.
data-fg-item-idThe item’s ID — used to fetch info panel data from the REST API.
data-fg-captionCaption text — shown in the info panel immediately (no REST fetch needed).
data-fg-titleTitle text — available in the item event object.

A minimal hand-authored gallery structure:

<div class="fotogrids-gallery" data-fg-click="lightbox" data-fg-lb-theme="dark">

    <figure>
        <a href="https://example.com/photo-full.jpg"
           data-fg-lightbox-trigger
           data-fg-item-id="42"
           data-fg-caption="Sunrise over the valley">
            <img src="https://example.com/photo-thumb.jpg" alt="Sunrise over the valley">
        </a>
    </figure>

    <figure>
        <a href="https://example.com/photo2-full.jpg"
           data-fg-lightbox-trigger
           data-fg-item-id="43"
           data-fg-caption="Golden hour">
            <img src="https://example.com/photo2-thumb.jpg" alt="Golden hour">
        </a>
    </figure>

</div>

The data-fg-lb-* Settings System #

All Lightbox settings are read from data-fg-lb-* attributes on the gallery wrapper at open time. The PHP renderer writes these from the gallery’s stored settings — but they can be set or overridden directly in HTML.

Boolean attributes: Present means enabled, absent means disabled — no value is needed (e.g. data-fg-lb-fit-media with no ="true"). The naming convention flips for no- prefixed attributes: data-fg-lb-no-loop present means loop is disabled.

Theme & Colors

AttributeTypeDefaultDescription
data-fg-lb-theme"dark" | "light" | "custom""dark"Color theme
data-fg-lb-bgrgba stringBackdrop color (custom theme)
data-fg-lb-toolbar-bgrgba stringToolbar background (custom theme)
data-fg-lb-toolbar-btn-colorrgba stringToolbar button icon color (custom theme)
data-fg-lb-toolbar-btn-hoverrgba stringToolbar button hover color (custom theme)
data-fg-lb-toolbar-btn-active-bgrgba stringActive button background (custom theme)
data-fg-lb-arrow-bgrgba stringArrow button background (custom theme)
data-fg-lb-arrow-bg-hoverrgba stringArrow button hover background (custom theme)
data-fg-lb-arrow-colorrgba stringArrow icon color (custom theme)
data-fg-lb-arrow-hover-colorrgba stringArrow icon hover color (custom theme)
data-fg-lb-bullet-colorrgba stringInactive dot color (custom theme)
data-fg-lb-bullet-hover-colorrgba stringDot hover color (custom theme)
data-fg-lb-bullet-active-colorrgba stringActive dot color (custom theme)
data-fg-lb-thumbs-bgrgba stringThumbnail strip background (custom theme)
data-fg-lb-thumb-border-colorrgba stringThumbnail border color (custom theme)
data-fg-lb-thumb-active-colorrgba stringActive thumbnail highlight (custom theme)
data-fg-lb-info-bgrgba stringInfo panel background (custom theme)
data-fg-lb-info-block-bgrgba stringInfo block background (custom theme, boxed style)
data-fg-lb-info-block-dividerrgba stringDivider color between blocks (custom theme, divided style)
data-fg-lb-info-textrgba stringInfo panel body text color (custom theme)
data-fg-lb-info-titlergba stringInfo panel title color (custom theme)
data-fg-lb-spinner-colorrgba stringLoading spinner color (custom theme)
data-fg-lb-img-shadowrgba stringItem shadow color (custom theme)
data-fg-lb-progress-colorrgba stringProgress bar/spinner color (custom theme)

Layout & Behavior

AttributeTypeDefaultDescription
data-fg-lb-overlay-blurinteger (px)8Backdrop blur intensity (attribute absent = 8; set to 0 for no blur)
data-fg-lb-fit-mediaboolean attrabsent = offScale items to fit the viewport
data-fg-lb-mobile-layout"mobile_optimized" | "desktop""mobile_optimized"Mobile layout mode
data-fg-lb-fullscreenboolean attrabsent = offShow fullscreen button
data-fg-lb-no-tooltipsboolean attrabsent = offPresent to disable button tooltips
data-fg-lb-no-backdrop-closeboolean attrabsent = offPrevent closing by clicking the backdrop

Navigation & Transition

AttributeTypeDefaultDescription
data-fg-lb-transition"fade" | "horizontal" | "vertical" | "none""fade"Transition style between items
data-fg-lb-durationinteger (ms)300Transition duration
data-fg-lb-no-loopboolean attrabsent = loop onPresent to disable looping
data-fg-lb-hide-arrows-at-endsboolean attrabsent = offHide arrows at first/last item when loop is off
data-fg-lb-show-arrowsboolean attrabsent = offShow prev/next navigation arrows
data-fg-lb-arrow-icon"chevron" | "chevron_double" | "arrow" | "arrow_narrow" | "arrow_square" | "arrow_circle" | "arrow_circle_broken" | "arrow_block""chevron"Arrow icon style
data-fg-lb-arrow-prevSVG stringPrevious arrow icon SVG (written by PHP from arrow-icons.json; override to supply a custom SVG)
data-fg-lb-arrow-nextSVG stringNext arrow icon SVG (written by PHP from arrow-icons.json; override to supply a custom SVG)
data-fg-lb-arrow-sizeinteger (px)40Arrow icon size
data-fg-lb-show-dotsboolean attrabsent = offShow dot navigation
data-fg-lb-dot-style"fill" | "stroke" | "square" | "square_stroke""fill"Dot style
data-fg-lb-dot-sizeinteger (px)12Dot size
data-fg-lb-dots-spacingCSS length"8px"Spacing between dots
data-fg-lb-show-counterboolean attrabsent = offShow item counter in toolbar

Auto-Progress

AttributeTypeDefaultDescription
data-fg-lb-auto-progressboolean attrabsent = offEnable auto-progress
data-fg-lb-auto-delayinteger (seconds)5Delay between auto-advances
data-fg-lb-progress-style"bar" | "spinner" | "none""bar"Progress indicator style
data-fg-lb-progress-bar-loc"top" | "right" | "bottom" | "left""bottom"Progress bar position
data-fg-lb-progress-pause-onspace-separated tokens"image_hover"What pauses auto-progress (image_hover, thumbnail_hover)
data-fg-lb-progress-stopboolean attrabsent = offStop permanently on user interaction
data-fg-lb-progress-controlsboolean attrabsent = offShow play/pause button in toolbar

Thumbnail Strip

AttributeTypeDefaultDescription
data-fg-lb-thumbnail-location"bottom" | "top" | "left" | "right" | "none""bottom"Strip position
data-fg-lb-thumbnail-size"small" | "normal" | "large""normal"Thumbnail size
data-fg-lb-thumb-spacinginteger (px)5Space between thumbnails
data-fg-lb-no-thumb-dragboolean attrabsent = drag onPresent to disable mouse drag
data-fg-lb-no-thumb-swipeboolean attrabsent = swipe onPresent to disable touch swipe

Zoom

AttributeTypeDefaultDescription
data-fg-lb-zoomboolean attrabsent = offEnable zoom
data-fg-lb-zoom-trigger"double_click" | "click" | "wheel_pinch""double_click"Zoom activation method
data-fg-lb-zoom-iconsboolean attrabsent = offShow zoom in/out buttons in toolbar
data-fg-lb-zoom-beyondboolean attrabsent = offAllow zoom beyond original resolution

Info Panel

AttributeTypeDefaultDescription
data-fg-lb-info-panel"always" | "on_click" | "never""always"Info panel visibility mode
data-fg-lb-info-location"left" | "right" | "bottom""right"Info panel position
data-fg-lb-info-blocksspace-separated block IDsall blocksWhich info blocks to render
data-fg-lb-info-blocks-style"boxed" | "divided" | "plain""boxed"Block layout style
data-fg-lb-credit-source"item_meta" | "exif""item_meta"Credit text source
data-fg-lb-exif-fieldsspace-separated field keys[]Which EXIF fields to show

Info block IDs (for data-fg-lb-info-blocks):
caption description file_info exif share credit tags people location rating download

EXIF field keys (for data-fg-lb-exif-fields):
camera aperture shutter_speed iso lens focal_length date_taken copyright orientation flash white_balance exposure_mode

Image Filters

AttributeTypeDescription
data-fg-lb-thumb-filterCSS filter stringFilter applied to thumbnail strip items
data-fg-lb-thumb-filter-hoverCSS filter stringFilter on thumbnail hover
data-fg-lb-full-filterCSS filter stringFilter applied to the main displayed item
data-fg-lb-full-filter-hoverCSS filter stringFilter on main item hover

Example: data-fg-lb-full-filter="grayscale(100%)" renders all items in black and white until hovered.


Info Panel REST Endpoint #

When a visitor opens an item, the Lightbox fetches extended metadata from:

GET /wp-json/fotogrids/v1/lightbox/item/{id}

Authentication: Public — no nonce or authentication required.

Path parameter:

ParameterTypeDescription
idintegerThe item ID from data-fg-item-id on the trigger element

Response shape:

{
    "id": 42,
    "caption": "Sunrise over the valley",
    "description": "Taken at 5:43am on the eastern ridge.",
    "credit": "© Jane Smith",
    "file_info": {
        "filename": "sunrise.jpg",
        "filesize": "2.4 MB",
        "width": 4000,
        "height": 2667,
        "mime_type": "image/jpeg"
    },
    "exif": {
        "camera": "Canon EOS R5",
        "aperture": "f/2.8",
        "shutter_speed": "1/250s",
        "iso": "400",
        "lens": "RF 85mm f/1.2L",
        "focal_length": "85mm",
        "date_taken": "2025-01-12 05:43:00",
        "copyright": "© Jane Smith",
        "orientation": "Landscape",
        "flash": "No Flash",
        "white_balance": "Auto",
        "exposure_mode": "Manual"
    },
    "tags": [
        { "id": 7, "name": "Landscape", "slug": "landscape" }
    ],
    "people": [
        { "id": 3, "name": "Jane Smith", "slug": "jane-smith" }
    ],
    "location": {
        "id": 5,
        "name": "Eastern Ridge",
        "slug": "eastern-ridge",
        "lat": 45.123,
        "lng": -122.456
    }
}

Fields not set for an item are returned as null (scalars) or [] (arrays). The Lightbox silently skips rendering any block whose data is null or empty.

Caching: Responses are cached in memory for the page session. Navigating back to a previously opened item shows cached data immediately without a second request.


The Lightbox Singleton #

The Lightbox is a singleton — one FotoGridsLightbox instance is created at page load and reused across all galleries on the page. It is accessible at:

window._fgLightbox   // internal reference — treat as read-only

Direct manipulation of the singleton is not a supported API and may change between versions. Use the custom events above as the stable integration surface.

Was this article helpful?