Render content in a modal dialog. Includes a trigger to open the dialog and a dialog element (<dialog/>) to display content.
Block Metadata
| Property | Value |
|---|---|
| Namespace | prc-block/dialog |
| Category | media |
| Version | 1.1.0 |
| API Version | 3 |
| Keywords | dialog, modal, popup |
| Example | Yes (with inner blocks — drives inserter preview) |
Supports
| Feature | Value |
|---|---|
| Anchor | false |
| HTML editing | false |
| List View | true |
| Font size | true (default controls enabled) |
| Font family | true (default controls enabled) |
| Interactivity | true |
Attributes
| Attribute | Type | Default | Role | Description |
|---|---|---|---|---|
dialogId | string | "" | — | Unique identifier for the dialog. Defaults to the block's clientId in the editor. Must be unique on the page. |
editorIsDialogOpen | boolean | false | local | Editor-only state tracking whether the dialog content is currently visible for editing. Not saved to post content. |
Provided Context
| Context Key | Source Attribute |
|---|---|
dialog/id | dialogId |
dialog/isOpen | editorIsDialogOpen |
Allowed Inner Blocks
prc-block/dialog-elementprc-block/dialog-trigger
Inner Blocks Template
The block initializes with a locked template:
- Dialog Trigger (
prc-block/dialog-trigger) — Contains a paragraph for trigger text. - Dialog Element (
prc-block/dialog-element) — Contains a heading bound to the dialog label.
Template lock is set to insert (blocks cannot be added/removed, but content can be edited).
Parent/Ancestor Requirements
None. This is the top-level container for dialog functionality.
Usage Instructions
- Insert the Dialog block from the block inserter (under the Media category, or search for "dialog", "modal", or "popup").
- Type trigger text in the Dialog Trigger area — this is what users will click to open the dialog.
- Click "Edit Dialog" in the block toolbar or inspector panel to reveal the dialog element for editing.
- Add content inside the Dialog Element (headings, paragraphs, images, etc.).
- Click "Close Dialog" to return to the trigger view.
- The Dialog ID can be customized in the inspector panel. It must be unique on the page.
- The dialog auto-opens for editing when you select the dialog element or its inner blocks.
Note: Editor inspector controls were updated for current WordPress component defaults (removed obsolete __next40pxDefaultSize props).
Block Markup Example
The example defined in block.json drives the inserter preview. It uses a bare dialog-trigger (no inner content) and a dialog-element with medium size and fade animation:
<!-- wp:prc-block/dialog {"dialogId":"123"} -->
<!-- wp:prc-block/dialog-trigger /-->
<!-- wp:prc-block/dialog-element {"dialogSize":"medium","animation":"fade"} /-->
<!-- /wp:prc-block/dialog -->
A more complete real-world example with inner content:
<!-- wp:prc-block/dialog {"dialogId":"my-dialog"} -->
<!-- wp:prc-block/dialog-trigger -->
<!-- wp:paragraph -->
<p>Click to open</p>
<!-- /wp:paragraph -->
<!-- /wp:prc-block/dialog-trigger -->
<!-- wp:prc-block/dialog-element {"dialogSize":"medium","animation":"fade"} -->
<!-- wp:heading -->
<h2>Dialog Title</h2>
<!-- /wp:heading -->
<!-- /wp:prc-block/dialog-element -->
<!-- /wp:prc-block/dialog -->
PHP Rendering
The Dialog PHP class provides a server-side render callback:
- Requires a
dialogIdattribute. If missing, outputs a_doing_it_wrongwarning and returns empty. - A
render_block_datafilter provides a fallback: if nodialogIdis set, it generates one viawp_unique_id('dialog-'). - Wraps inner content in a
<div>with Interactivity API directives:data-wp-interactive="prc-block/dialog",data-wp-context(containing the dialog ID), anddata-wp-key.
Rendered output:
<div
class="wp-block-prc-block-dialog"
data-wp-interactive="prc-block/dialog"
data-wp-context='{"id":"my-dialog"}'
data-wp-key="my-dialog"
>
<!-- trigger and dialog element content -->
</div>
Frontend Interactivity
The Dialog block itself serves as the container. The actual interactivity logic lives in the prc-block/dialog-element view script (see dialog-element.md). The dialog block establishes the Interactivity API context that its children consume.
Related Blocks
prc-block/dialog-trigger— The clickable trigger element (required child).prc-block/dialog-element— The modal dialog content container (required child).