Random Image
A Bricks element that shows one or more randomly chosen photos from hand-picked images, a media library query, a post type query or an ACF field, without repeating a photo on the same page.
Version: 1.0.5 · Requires: PHP 7.4+, Bricks · See the live demo
What it does
- Four sources, deduplication across elements on a page, optional daily-stable selection.
- Only the pool of candidates is cached, never the random pick.
- Single image or a grid, with optional link, caption and overlay.
Installation
- Upload and activate the plugin. Bricks must be active.
- In the Bricks editor search for Random Image (General group).
Data source
- Selected images — Pick images in the Media Library. The picker’s size overrides Image Size.
- Media Library query (default) — Media category (slug or ID,
media_categorytaxonomy), include IDs, exclude IDs, max pool size (200) - Custom post type query — Post type, taxonomy, term slugs or IDs, image source per post (Featured image / ACF field), ACF field name, max pool size (100)
- ACF field — Field name, repeater image subfield, field location (Current post / Specific post ID / Options page), post ID
If ACF is not active, ACF sources return an empty pool.
Query and randomisation
- Number of images — 1
- Image size — Large (default), Thumbnail, Medium, Full
- Randomisation mode — Random on every page load (default), Stable for the day (same for all visitors until midnight UTC)
- Deduplication scope — Shared with other Random Image elements on the page (default), This element only
- Custom registry key — Same key on several instances groups them
- Allow repeats if pool exhausted — On
Link, caption, performance, layout
Link
- Enable link — Off
- Link type — Lightbox (full-size image), Attachment / source post page, Custom URL, Dynamic data tag
- Open in new tab — Off
Caption and overlay
- Show caption — Off
- Caption source — Attachment caption (default), alt text, title, ACF field, custom text
- Position — Below (default), Overlay bottom, top, centre
- Overlay background / text colour — rgba(0,0,0,0.55) / white
Performance
- Cache image pool query — On, 15 minutes
- Lazy load images — On
Layout (Style tab)
- Aspect ratio — 16:9 (default), Auto, 1:1, 4:3, 3:2, 21:9, Custom
- Object fit — Cover (default), Contain, Fill
- Grid columns — 3 (1 to 8), settable per breakpoint
- Grid gap —
16px - Image border radius —
0px
To refresh every cached pool at once, use Clear Random Image Cache in the front-end admin bar (administrators), or do_action( 'nl_random_image_clear_cache' );.
Known limits
- The Lightbox link type uses the Bricks lightbox (PhotoSwipe), loaded only when links are on.
- A few Bricks-version-sensitive calls are flagged in the code for checking against the installed Bricks version.