Hooks

Docs Developers

Hooks and filters.

Every filter and action in Modal Kit and Modal Kit Pro, and the JavaScript filters for the editor and settings screens. Each page has the hook’s arguments, what it returns and code you can paste into your own plugin.

For the architecture, the browser events, the REST routes and opening a modal from your own script, see the Developers page.

Where the code goes

PHP hooks: a small plugin of your own

Put PHP snippets in your own plugin or a must‑use plugin, not in Modal Kit’s files, so updates don’t remove them. A file in wp-content/mu-plugins/ loads on every request with nothing to activate. Add a hook before WordPress fires init, as plugins usually do: some of Modal Kit’s values are read early in init, and each page says when that matters.

PHP · wp-content/mu-plugins/my-modal-kit.php

<?php
/**
 * Plugin Name: My Modal Kit tweaks
 */

defined( 'ABSPATH' ) || exit;

add_filter( 'modal_kit_close_label', function ( $label, $post_id ) {
  return __( 'Close this offer', 'my-plugin' );
}, 10, 2 );

Editor filters: a script on the right screen

The editor filters run in the browser, through wp.hooks. Build your script with @wordpress/scripts and load it on the screen that applies the filter, before that screen’s app starts. For the modal editor, enqueue on enqueue_block_editor_assets for the mk_modal post type and depend on modal-kit-editor. For Modal Kit → Settings, enqueue on admin_enqueue_scripts when the hook suffix is mk_modal_page_modal-kit-settings and depend on modal-kit-settings. Each filter’s page names its screen.

PHP · loading an editor script

add_action( 'enqueue_block_editor_assets', function () {
  $screen = get_current_screen();
  if ( ! $screen || 'mk_modal' !== $screen->post_type ) {
    return;
  }

  $asset = require __DIR__ . '/build/editor.asset.php';
  wp_enqueue_script(
    'my-plugin-modal-editor',
    plugins_url( 'build/editor.js', __FILE__ ),
    array_merge( $asset['dependencies'], array( 'modal-kit-editor' ) ),
    $asset['version'],
    true
  );
}, 20 );

add_action( 'admin_enqueue_scripts', function ( $hook_suffix ) {
  if ( 'mk_modal_page_modal-kit-settings' !== $hook_suffix ) {
    return;
  }

  $asset = require __DIR__ . '/build/settings.asset.php';
  wp_enqueue_script(
    'my-plugin-modal-settings',
    plugins_url( 'build/settings.js', __FILE__ ),
    array_merge( $asset['dependencies'], array( 'modal-kit-settings' ) ),
    $asset['version'],
    true
  );
}, 20 );

Every hook

Free · PHP hooks

Pro · PHP hooks

Pro · Updates

Editor filters · JavaScript

Need a hook that isn’t here?