Overview

A Bootstrap modal built from inner blocks. It opens from any link or button that points at its ID, is not shown where the block sits, and is printed at the end of the page by Method’s modal registry.


Usage

Insert a Modal anywhere — a page, a template part, a synced pattern — and build its content from blocks. The block gets an ID the first time it is edited (modal- plus six random characters) that never changes afterwards; Link and ID shows it with a Copy button, and the block toolbar has Copy link. Point any link or button at #that-id and it opens the modal; nothing is added to the link itself. A Custom ID overrides the generated one (lowercased, runs of other characters become -); clearing it falls back to the generated ID. A duplicated or pasted modal takes a fresh generated ID, and a custom ID copied from the original is cleared, while the block that was already there keeps its ID.

The modal is laid out in place in the editor, under a bar showing its ID, size and options, but on the page the block prints nothing where it sits: a Bootstrap modal inside a Section would sit in the section’s stacking context, under the body-level backdrop. The render callback hands the rendered content to the registry, which prints every modal on wp_footer. The Modals panel in the document sidebar lists every modal in the document with its ID and size, warns when two share an ID, and can add one. How modals reach the page, the PHP API, the hooks and the opening script are documented on the Modals system page; this page covers the block.


Attributes

AttributeTypeDefaultDescription
modalIdstring""Generated ID, kept stable by usePersistentId. Sanitised on render by method_sanitize_modal_id().
customIdstring""Optional ID that takes precedence over modalId. The effective ID is method_modal_get_block_id() in PHP and getEffectiveModalId() in lib/blocks/utils/modalId.js.
titlestring""The heading, edited in the canvas (RichText) or in the Modal panel; stored as HTML, printed through wp_kses() with no tags allowed.
hideTitlebooleanfalseKeeps the heading in the markup as .visually-hidden, so it still labels the dialog through aria-labelledby.
titleTagstring"h2"Heading element: h1–h6, p or div.
sizestring"default"One of the keys of method_get_modal_sizes(): sm (300px), default (500px), lg (800px), xl (1140px), fullscreen. The width is printed as --method-modal-width on the modal and capped to the viewport.
fullscreenBelowstring"""" (never), mobile or tablet: the modal goes full screen at that tier and below, with one CSS rule per tier built from method_get_block_breakpoints() (Method_Modals::get_fullscreen_css()). The option labels show the theme’s actual breakpoints.
centeredbooleanfalseAdds modal-dialog-centered.
scrollablebooleanfalseAdds modal-dialog-scrollable: the body scrolls inside a modal taller than the viewport.
staticBackdropbooleanfalsePrints data-bs-backdrop="static": a click on the backdrop no longer closes the modal.
closeIconstring""Slug of an icon registered through theme icons for the close button; empty is the default stroke ×. The panel only appears when the theme registers icons.
textColorstring—Text color of .modal-content.
linkColorstring—Color of links in the body (except .method-theme-button).
bgColorstring—Background color of .modal-content.
bgGradientstring—Background gradient of .modal-content.
responsiveSettingsobject{"base":{"enabled":true},…}Per-tier padding, border and radius; see below.

responsiveSettings Structure

Per-tier settings live under responsiveSettings.base, mobile, tablet and wide. A tier is only read while its enabled flag is true; base is always on. The keys this block’s CSS map reads:

  • padding.top → .modal-header; padding.bottom → .modal-body; padding.left, padding.right → both. The padding is the modal’s inner frame, so one set of four values is split between the header and the body. The control’s reset value is 1rem on every side.
  • border, borderRadius → .modal-content.

Control Sets

ComponentPanelBreakpointsNotes
Block panel: ModalModalbaseTitle, Hide title, Title tag.
Block panel: Link and IDLink and IDbaseThe effective ID with Copy, Custom ID, and notices when another modal or a block anchor on the page uses the same ID.
Block panel: LayoutLayoutbaseSize, Full screen (below a tier; hidden for the full-screen size), Vertically centered, Scrollable body, Static backdrop.
Block panel: Close buttonClose buttonbaseIcon — only when the theme registers icons.
MethodSpacingControlsSpacingbase + mobile / tablet / wideinclude={['padding']}, all four sides, reset to 1rem.
MethodBorderControlsBorderbase + mobile / tablet / wideBorder and radius.
MethodColorControlsColor Settingsbaseinclude={['textColor', 'linkColor', 'bgColor']}
MethodResponsiveTabsMobile / Tablet / Ultrawidemobile, tablet, wideSpacing and border per tier.
MethodStyleTag—allMirrors $cssargs in the canvas.
usePersistentId——Keeps modalId stable and regenerates it on copies (lib/blocks/hooks/usePersistentId.js).
useCanvasViewport——The preview goes full screen at the same canvas widths as the frontend.

Data & Dependencies

  • Registry: Method_Modals (lib/class-method-modals.php) — the render callback calls method_register_modal() with the block’s id, title, rendered content, source => 'block', the wrapper classes (wp-block-method-modal plus the block’s className), its generated CSS, its assets and its options. The first registration of an id wins; later ones are dropped (and a duplicate fires method/modal_duplicate). Modals are printed on wp_footer at priority 5, with a second pass at 19 for late registrations.
  • Sizes: method_get_modal_sizes() (filterable with method/modal_sizes) supplies the Layout panel through methodModalData.sizes, localised on enqueue_block_editor_assets.
  • Assets of an empty block: since WordPress 6.9, assets enqueued while rendering a block that prints nothing are dequeued. The block opts out through the enqueue_empty_block_content_assets filter (method_modal_keep_assets()), and because the same happens one level up when the block around a modal prints nothing (a synced pattern holding only a modal), method_modal_snapshot_assets() on render_block_data notes what the content enqueues so the registry can enqueue it again once the page has rendered (snapshot_assets() / assets_since_snapshot()).
  • Nowhere to print: the callback returns early during REST requests and feeds, for a block hidden with block visibility (metadata.blockVisibility === false), for a block with no id yet, and for an id already registered.
  • Opening: the view script (method-modal-view-script, which depends on the method bundle for window.bootstrap.Modal) is enqueued by the registry only on pages that have a modal. One delegated click handler opens the modal a link points at (#id, or a full URL to the current page with that hash); links are decorated with data-method-modal-trigger, aria-haspopup="dialog", aria-controls and role="button"; a URL hash on load opens that modal. window.methodModals.open( idOrElement, trigger ) and decorate( root ) serve links added later.
  • Styles: structural Bootstrap 5.3 modal rules wrapped in :where() (zero specificity, so a child theme’s own .modal rules win), plus .method-modal for the fade, the width, full screen and the close button, in assets/scss/global.scss; editor preview styles under .method-modal-editor.
  • Responsive CSS: method_get_block_responsive_styles(), collected by the registry under #id.method-modal when the modal prints.

Frontend Rendering

The block prints nothing in place. Method_Modals::get_markup() prints this in the footer (a default-size modal with a title):

HTML
<div class="modal fade method-modal wp-block-method-modal" id="modal-k3x9pq" tabindex="-1" aria-hidden="true" data-method-modal-scope="post" aria-labelledby="modal-k3x9pq-title" style="--method-modal-width:500px">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="modal-k3x9pq-title">Request a quote</h2>
        <button type="button" class="method-modal-close" data-bs-dismiss="modal" aria-label="Close"><span class="method-modal-close-icon" aria-hidden="true"><svg …></svg></span></button>
      </div>
      <div class="modal-body">
        <div class="wp-block-method-modal method-modal-inner-blocks">
          …the inner blocks, rendered…
        </div>
      </div>
    </div>
  </div>
</div>

Variations: .modal-dialog gains modal-sm / modal-lg / modal-xl / modal-fullscreen for the size, modal-dialog-centered, modal-dialog-scrollable, and method-modal-fullscreen-mobile or -tablet for full screen below a tier; a hidden title keeps the heading with visually-hidden; a modal without a title gets aria-label="Dialog" instead of aria-labelledby; a static backdrop adds data-bs-backdrop="static"; a custom close icon adds method-modal-close-icon-custom. The close button is button.method-modal-close, not Bootstrap’s .btn-close, so existing .btn-close styling in a child theme is untouched.

Generated CSS (per modal, scoped to #id.method-modal): … .modal-content → text and background color, border, radius; … .modal-header → top, left and right padding; … .modal-body → bottom, left and right padding; … .modal-body a:not(.method-theme-button) → linkColor.


Filters

The block itself adds no hooks. Everything it registers passes through the registry’s — method/modal_args (return false to skip a modal), method/modal_content, method/modal_markup, method/modal_sizes and method/modal_script_dependencies, and the method/modal_registered and method/modal_duplicate actions — which are documented, with method_register_modal() and the method/register_modals action, on the Modals page. The block also uses two core filters: enqueue_empty_block_content_assets and render_block_data (see Data & Dependencies).

PHP
// Skip every block modal on the search results page.
add_filter( 'method/modal_args', function ( $args ) {
    if ( is_search() && 'block' === ( $args['source'] ?? '' ) ) {
        return false;
    }
    return $args;
} );

Changelog

VersionDescription
2.0.0-beta26Introduced, with the modal registry, the Modals sidebar panel and the opening script (e12c9c0).
2.0.0-beta27The registry’s asset snapshot reads the script-module queue on WordPress 6.5–6.8 as well as 6.9+, so the block’s effective floor is 6.5 (b0c9c42).