Modal for Bricks
A nestable Bricks element built on the native <dialog> element. Put any Bricks elements inside it and choose when it opens.
Version: 1.0.0 · Requires: Bricks 1.9+, WordPress 6.5+, PHP 8.1+ · See the live demo
Installation
- Upload and activate the plugin. Bricks must be active.
- Add the Modal element (General). Drop content inside it.
- Give it a Modal ID (for example
booking) and add a trigger, or link to it.
Opening a modal
- Link:
<a href="#booking">, or any element withdata-nlm-open="booking". - Triggers (Triggers group, add as many as you like): page load, URL parameter, scroll distance, scroll to element, exit intent, after N page views, inactivity, click on a selector, hover on a selector. Several triggers combine with OR (any) or AND (all).
- JavaScript:
NLModal.open("booking").
Reshow rules
Apply to automatic triggers only: Always, Never again, After a set number of days & hours, Once per page visit, Once per session. Click and hover triggers, links and the API always open the modal. The memory is stored in the visitor’s browser. NLModal.reset("booking") clears it.
Settings
- Position: nine positions, plus margin from the edge, width, maximum height and content padding.
- Animation: none, fade, zoom or four slides for opening and closing, with a duration in ms. For visitors who prefer reduced motion: plain fade, none, or keep.
- Behaviour: lock page scroll, Esc closes, click on backdrop closes,
#hashlinks inside close it, reset forms on close, do not move focus on open. - Close button: icon, label, size, colours, or remove it and add
data-nlm-closeto any inner element. - Accessibility: accessible name and role (dialog or alertdialog). Triggers get
aria-controls,aria-haspopupandaria-expanded. - Style: backdrop colour, background, border and shadow. CSS variables:
--nlm-width,--nlm-margin,--nlm-max-height,--nlm-bg,--nlm-backdrop,--nlm-close-size.
Events and API
nlmodal:openandnlmodal:closebubble from the element.detail.idholds the Modal ID.NLModal.open(id),.close(id),.closeAll(),.isOpen(id),.reset(id).
Tips
- Use a Modal ID you can read, so links and the API stay obvious.
- Keep automatic modals to one per page and set a reshow rule so visitors are not nagged.
Known limits
- In the builder the content is shown inline and nothing opens.
- Exit intent on touch screens uses a quick scroll to the top as the signal.