Hooks

Docs Hooks Free · PHP hooks

modal_kit_close_label

filter

Free

PHP

Change the close button’s label for one modal or all of them: read aloud for the × button, or shown as text when the label is visible.

Runs on the server each time a modal is rendered for the front end. When the close button shows the × icon only, the label is its aria-label; when the modal shows the label as text, it’s the button’s visible text.

The value passed in is the modal’s own Close button label from its Accessibility panel, or the site default from Modal Kit → Settings → Accessibility, or a translated “Close” when both are empty.

Parameters

Parameter

Description

$label

string

The label from the modal’s Accessibility panel or the site default, or “Close”.

$post_id

int

The modal’s post ID. 0 for the sample modal in the Modal Kit → Settings → Display preview.

Returns

string The label. Return a non-empty string: when the label isn’t shown, it is the button’s only accessible name.

Examples

Name the button after the modal

Screen reader users hear which dialog the button closes. The Display preview passes 0, so it keeps the default.

PHP

add_filter( 'modal_kit_close_label', function ( $label, $post_id ) {
  $title = $post_id ? get_the_title( $post_id ) : '';

  if ( '' === $title ) {
    return $label;
  }

  return sprintf(
    /* translators: %s: modal title */
    __( 'Close %s', 'my-plugin' ),
    $title
  );
}, 10, 2 );

Use the same wording on every modal

This replaces the site default and every modal’s own label.

PHP

add_filter( 'modal_kit_close_label', function () {
  return __( 'Close this window', 'my-plugin' );
} );

Good to know

The value is cast to a string, and escaped with esc_attr() or esc_html() when printed.

The label is part of the page’s HTML, so it survives a static export.

The editor canvas always shows “Close”: the filter changes the front end only.

Applied in modal-kit/includes/Render.php.

Need a hook that isn’t here?