Hooks

Docs Hooks Free · PHP hooks

modal_kit_pattern_categories

filter

Free

PHP

Add, rename or remove the categories in the template picker. Starters you register in your own category show up next to Modal Kit’s.

Filters the categories of the template picker, the dialog titled Choose a starting layout on a new modal and Change template later. Each slug is registered as a block pattern category on init (priority 20), and the labels are passed to the modal editor.

A registered block pattern becomes a starter in the picker when one of its categories is in this list or in modal_kit_pattern_collections. The picker sorts categories A–Z and hides the ones with no starters.

Parameters

Parameter

Description

$categories

array<string, string>

Slug => label. Defaults: modal-kit-newsletter (Newsletter), modal-kit-promo (Promo & discount), modal-kit-announcement (Announcement), modal-kit-exit (Exit offer) and modal-kit-video (Video).

Returns

array<string, string> Slug => label, cast to an array.

Examples

Add a category for your own starters

Register the starter as a block pattern. inserter => false keeps it out of the block inserter, as Modal Kit does with its own.

PHP

add_filter( 'modal_kit_pattern_categories', function ( $categories ) {
  $categories['my-plugin-events'] = __( 'Events', 'my-plugin' );

  return $categories;
} );

add_action( 'init', function () {
  register_block_pattern(
    'my-plugin/webinar-reminder',
    array(
      'title'      => __( 'Webinar reminder', 'my-plugin' ),
      'categories' => array( 'my-plugin-events' ),
      'postTypes'  => array( 'mk_modal' ),
      'inserter'   => false,
      'content'    => '<!-- wp:modal-kit/modal -->'
        . '<!-- wp:heading --><h2 class="wp-block-heading">'
        . esc_html__( 'Our webinar starts soon', 'my-plugin' )
        . '</h2><!-- /wp:heading -->'
        . '<!-- wp:paragraph --><p>'
        . esc_html__( 'Save your seat. It is free.', 'my-plugin' )
        . '</p><!-- /wp:paragraph -->'
        . '<!-- /wp:modal-kit/modal -->',
    )
  );
} );

Rename a category

PHP

add_filter( 'modal_kit_pattern_categories', function ( $categories ) {
  if ( isset( $categories['modal-kit-promo'] ) ) {
    $categories['modal-kit-promo'] = __( 'Sales', 'my-plugin' );
  }

  return $categories;
} );

Good to know

Add the filter before init priority 20, when the categories are registered. The picker reads patterns from the block pattern registry, so register yours on init with register_block_pattern().

Pattern content without a Modal block is wrapped in a default one when it’s picked.

A pattern registered for the mk_modal post type but in none of these categories or collections is listed under From your theme.

Every starter with a video or embed block is also listed under Video, whatever its categories.

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

Need a hook that isn’t here?