---
title: "modalKit.triggerTypes – Modal Kit Docs"
description: "Add automatic trigger types to the Triggers panel’s Add trigger menu, each with a label, description, defaults and its own settings."
language: "en-US"
canonical_url: "https://modalkitwp.com/docs/hooks/modalkit-triggertypes/"
source_url: "https://modalkitwp.com/docs/hooks/modalkit-triggertypes/"
content_type: "text/markdown"
---

[All hooks](https://modalkitwp.com/docs/hooks/)

Free · PHP hooks

[modal_kit_layouts](https://modalkitwp.com/docs/hooks/modal_kit_layouts/)

[modal_kit_styles](https://modalkitwp.com/docs/hooks/modal_kit_styles/)

[modal_kit_theme_tokens](https://modalkitwp.com/docs/hooks/modal_kit_theme_tokens/)

[modal_kit_meta_schema](https://modalkitwp.com/docs/hooks/modal_kit_meta_schema/)

[modal_kit_targets_request](https://modalkitwp.com/docs/hooks/modal_kit_targets_request/)

[modal_kit_dialog_context](https://modalkitwp.com/docs/hooks/modal_kit_dialog_context/)

[modal_kit_dialog_panel](https://modalkitwp.com/docs/hooks/modal_kit_dialog_panel/)

[modal_kit_button_actions](https://modalkitwp.com/docs/hooks/modal_kit_button_actions/)

[modal_kit_render_button_action](https://modalkitwp.com/docs/hooks/modal_kit_render_button_action/)

[modal_kit_link_prefix](https://modalkitwp.com/docs/hooks/modal_kit_link_prefix/)

[modal_kit_close_label](https://modalkitwp.com/docs/hooks/modal_kit_close_label/)

[modal_kit_post_type_capabilities](https://modalkitwp.com/docs/hooks/modal_kit_post_type_capabilities/)

[modal_kit_pattern_categories](https://modalkitwp.com/docs/hooks/modal_kit_pattern_categories/)

[modal_kit_pattern_collections](https://modalkitwp.com/docs/hooks/modal_kit_pattern_collections/)

[modal_kit_pattern_collection_types](https://modalkitwp.com/docs/hooks/modal_kit_pattern_collection_types/)

[modal_kit_starter_settings](https://modalkitwp.com/docs/hooks/modal_kit_starter_settings/)

[modal_kit_backdrop_capability](https://modalkitwp.com/docs/hooks/modal_kit_backdrop_capability/)

[modal_kit_backdrop_request](https://modalkitwp.com/docs/hooks/modal_kit_backdrop_request/)

[modal_kit_optimizer_paths](https://modalkitwp.com/docs/hooks/modal_kit_optimizer_paths/)

[modal_kit_pro_listings](https://modalkitwp.com/docs/hooks/modal_kit_pro_listings/)

Pro · PHP hooks

[modal_kit_pro_providers](https://modalkitwp.com/docs/hooks/modal_kit_pro_providers/)

[modal_kit_pro_captcha_providers](https://modalkitwp.com/docs/hooks/modal_kit_pro_captcha_providers/)

[modal_kit_pro_captcha_hostnames](https://modalkitwp.com/docs/hooks/modal_kit_pro_captcha_hostnames/)

[modal_kit_pro_country](https://modalkitwp.com/docs/hooks/modal_kit_pro_country/)

[modal_kit_pro_country_sources](https://modalkitwp.com/docs/hooks/modal_kit_pro_country_sources/)

[modal_kit_pro_results_goal](https://modalkitwp.com/docs/hooks/modal_kit_pro_results_goal/)

[modal_kit_pro_results_count](https://modalkitwp.com/docs/hooks/modal_kit_pro_results_count/)

[modal_kit_pro_coupon_issued](https://modalkitwp.com/docs/hooks/modal_kit_pro_coupon_issued/)

[modal_kit_pro_visitor_address](https://modalkitwp.com/docs/hooks/modal_kit_pro_visitor_address/)

[modal_kit_pro_play_rate_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_play_rate_limit/)

[modal_kit_pro_form_daily_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_form_daily_limit/)

[modal_kit_pro_address_daily_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_address_daily_limit/)

[modal_kit_pro_events_rate_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_events_rate_limit/)

[modal_kit_pro_modal_events_per_hour](https://modalkitwp.com/docs/hooks/modal_kit_pro_modal_events_per_hour/)

Pro · Updates

[modal_kit_pro_is_staging](https://modalkitwp.com/docs/hooks/modal_kit_pro_is_staging/)

[modal_kit_pro_pre_rollback](https://modalkitwp.com/docs/hooks/modal_kit_pro_pre_rollback/)

[modal_kit_pro_tested_up_to](https://modalkitwp.com/docs/hooks/modal_kit_pro_tested_up_to/)

Editor filters · JavaScript

[modalKit.layouts](https://modalkitwp.com/docs/hooks/modalkit-layouts/)

[modalKit.triggerTypes](https://modalkitwp.com/docs/hooks/modalkit-triggertypes/)

[modalKit.triggerMenuGroups](https://modalkitwp.com/docs/hooks/modalkit-triggermenugroups/)

[modalKit.buttonActions](https://modalkitwp.com/docs/hooks/modalkit-buttonactions/)

[modalKit.canvasChrome](https://modalkitwp.com/docs/hooks/modalkit-canvaschrome/)

[modalKit.styleTarget](https://modalkitwp.com/docs/hooks/modalkit-styletarget/)

[modalKit.settingsTabs](https://modalkitwp.com/docs/hooks/modalkit-settingstabs/)

[modalKit.styleEditor](https://modalkitwp.com/docs/hooks/modalkit-styleeditor/)

[modalKit.toolsRows](https://modalkitwp.com/docs/hooks/modalkit-toolsrows/)

[modalKit.pickerPreview](https://modalkitwp.com/docs/hooks/modalkit-pickerpreview/)

Hooks ▾

[All hooks](https://modalkitwp.com/docs/hooks/)

Free · PHP hooks

[modal_kit_layouts](https://modalkitwp.com/docs/hooks/modal_kit_layouts/)

[modal_kit_styles](https://modalkitwp.com/docs/hooks/modal_kit_styles/)

[modal_kit_theme_tokens](https://modalkitwp.com/docs/hooks/modal_kit_theme_tokens/)

[modal_kit_meta_schema](https://modalkitwp.com/docs/hooks/modal_kit_meta_schema/)

[modal_kit_targets_request](https://modalkitwp.com/docs/hooks/modal_kit_targets_request/)

[modal_kit_dialog_context](https://modalkitwp.com/docs/hooks/modal_kit_dialog_context/)

[modal_kit_dialog_panel](https://modalkitwp.com/docs/hooks/modal_kit_dialog_panel/)

[modal_kit_button_actions](https://modalkitwp.com/docs/hooks/modal_kit_button_actions/)

[modal_kit_render_button_action](https://modalkitwp.com/docs/hooks/modal_kit_render_button_action/)

[modal_kit_link_prefix](https://modalkitwp.com/docs/hooks/modal_kit_link_prefix/)

[modal_kit_close_label](https://modalkitwp.com/docs/hooks/modal_kit_close_label/)

[modal_kit_post_type_capabilities](https://modalkitwp.com/docs/hooks/modal_kit_post_type_capabilities/)

[modal_kit_pattern_categories](https://modalkitwp.com/docs/hooks/modal_kit_pattern_categories/)

[modal_kit_pattern_collections](https://modalkitwp.com/docs/hooks/modal_kit_pattern_collections/)

[modal_kit_pattern_collection_types](https://modalkitwp.com/docs/hooks/modal_kit_pattern_collection_types/)

[modal_kit_starter_settings](https://modalkitwp.com/docs/hooks/modal_kit_starter_settings/)

[modal_kit_backdrop_capability](https://modalkitwp.com/docs/hooks/modal_kit_backdrop_capability/)

[modal_kit_backdrop_request](https://modalkitwp.com/docs/hooks/modal_kit_backdrop_request/)

[modal_kit_optimizer_paths](https://modalkitwp.com/docs/hooks/modal_kit_optimizer_paths/)

[modal_kit_pro_listings](https://modalkitwp.com/docs/hooks/modal_kit_pro_listings/)

Pro · PHP hooks

[modal_kit_pro_providers](https://modalkitwp.com/docs/hooks/modal_kit_pro_providers/)

[modal_kit_pro_captcha_providers](https://modalkitwp.com/docs/hooks/modal_kit_pro_captcha_providers/)

[modal_kit_pro_captcha_hostnames](https://modalkitwp.com/docs/hooks/modal_kit_pro_captcha_hostnames/)

[modal_kit_pro_country](https://modalkitwp.com/docs/hooks/modal_kit_pro_country/)

[modal_kit_pro_country_sources](https://modalkitwp.com/docs/hooks/modal_kit_pro_country_sources/)

[modal_kit_pro_results_goal](https://modalkitwp.com/docs/hooks/modal_kit_pro_results_goal/)

[modal_kit_pro_results_count](https://modalkitwp.com/docs/hooks/modal_kit_pro_results_count/)

[modal_kit_pro_coupon_issued](https://modalkitwp.com/docs/hooks/modal_kit_pro_coupon_issued/)

[modal_kit_pro_visitor_address](https://modalkitwp.com/docs/hooks/modal_kit_pro_visitor_address/)

[modal_kit_pro_play_rate_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_play_rate_limit/)

[modal_kit_pro_form_daily_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_form_daily_limit/)

[modal_kit_pro_address_daily_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_address_daily_limit/)

[modal_kit_pro_events_rate_limit](https://modalkitwp.com/docs/hooks/modal_kit_pro_events_rate_limit/)

[modal_kit_pro_modal_events_per_hour](https://modalkitwp.com/docs/hooks/modal_kit_pro_modal_events_per_hour/)

Pro · Updates

[modal_kit_pro_is_staging](https://modalkitwp.com/docs/hooks/modal_kit_pro_is_staging/)

[modal_kit_pro_pre_rollback](https://modalkitwp.com/docs/hooks/modal_kit_pro_pre_rollback/)

[modal_kit_pro_tested_up_to](https://modalkitwp.com/docs/hooks/modal_kit_pro_tested_up_to/)

Editor filters · JavaScript

[modalKit.layouts](https://modalkitwp.com/docs/hooks/modalkit-layouts/)

[modalKit.triggerTypes](https://modalkitwp.com/docs/hooks/modalkit-triggertypes/)

[modalKit.triggerMenuGroups](https://modalkitwp.com/docs/hooks/modalkit-triggermenugroups/)

[modalKit.buttonActions](https://modalkitwp.com/docs/hooks/modalkit-buttonactions/)

[modalKit.canvasChrome](https://modalkitwp.com/docs/hooks/modalkit-canvaschrome/)

[modalKit.styleTarget](https://modalkitwp.com/docs/hooks/modalkit-styletarget/)

[modalKit.settingsTabs](https://modalkitwp.com/docs/hooks/modalkit-settingstabs/)

[modalKit.styleEditor](https://modalkitwp.com/docs/hooks/modalkit-styleeditor/)

[modalKit.toolsRows](https://modalkitwp.com/docs/hooks/modalkit-toolsrows/)

[modalKit.pickerPreview](https://modalkitwp.com/docs/hooks/modalkit-pickerpreview/)

[Docs](https://modalkitwp.com/docs/) / [Hooks](https://modalkitwp.com/docs/hooks/) / Editor filters · JavaScript

# `modalKit.triggerTypes`

filter

Free

JavaScript

Add automatic trigger types to the Triggers panel’s Add trigger menu, each with a label, description, defaults and its own settings.

Runs each time the **Triggers** panel renders, in Free’s `modal-kit-editor` script on the block editor for a modal. The panel lists the modal’s automatic triggers, and the **Add trigger** menu offers every type. Adding one stores `{ type, ...defaults }` in the modal’s `_modal_kit_triggers` meta.

Modal Kit Pro adds its WooCommerce triggers (Quick view button, Added to cart, Removed from cart, Cart total over…, Product or category in cart) in a **Shop** group, on sites with WooCommerce.

## Parameters

Parameter

Description

`types`

Object

Trigger types by name: `load`, `scroll`, `exit`, `time`, `inactivity`, `url` and `element`, plus any added by other plugins. Each has `label`, `description` (shown in the menu) and `defaults` (the settings a new trigger starts with).

## Returns

`Object` Types by name. A type may also set `Settings`, a component that receives `{ trigger, set }`, where `set( changes )` merges changes into the trigger, and `group`, a heading that puts the type in its own section of the menu.

## Examples

### Open when the visitor comes back to the tab

The editor side: a type with one setting.

JavaScript

```
import { __ } from '@wordpress/i18n';
import { addFilter } from '@wordpress/hooks';
import { TextControl } from '@wordpress/components';

function TabReturnSettings( { trigger, set } ) {
  return (
    <TextControl
      __next40pxDefaultSize
      __nextHasNoMarginBottom
      type="number"
      min={ 0 }
      label={ __( 'Seconds away, at least', 'my-plugin' ) }
      value={ trigger.away ?? 10 }
      onChange={ ( away ) =>
        set( { away: Math.max( 0, parseInt( away, 10 ) || 0 ) } )
      }
    />
  );
}

addFilter( 'modalKit.triggerTypes', 'my-plugin/tab-return', ( types ) => ( {
  ...types,
  'my-tab-return': {
    label: __( 'Back to the tab', 'my-plugin' ),
    description: __( 'The visitor returns from another tab', 'my-plugin' ),
    defaults: { away: 10 },
    Settings: TabReturnSettings,
  },
} ) );
```

### Allow the type when the modal saves

The triggers meta is checked against a JSON schema that lists the allowed types and fields. Add this when your plugin loads: Free registers the meta on `init`.

PHP

```
add_filter(
  'modal_kit_meta_schema',
  function ( $schema, $key ) {
    if ( 'triggers' !== $key ) {
      return $schema;
    }

    $schema['items']['properties']['type']['enum'][] = 'my-tab-return';
    $schema['items']['properties']['away']           = array(
      'type'    => 'integer',
      'minimum' => 0,
      'maximum' => 3600,
    );

    return $schema;
  },
  10,
  2
);
```

### Open the modal on the front end

Free’s runtime skips trigger types it doesn’t know, so a front-end script of yours does the opening. Load it in the footer with `wp_enqueue_scripts`: Free prints the modals early in `wp_footer`. It runs in the browser, so it works on a static export.

JavaScript

```
document.querySelectorAll( 'dialog.modal-kit' ).forEach( ( dialog ) => {
  let context = {};

  try {
    context = JSON.parse( dialog.dataset.wpContext || '{}' );
  } catch ( error ) {
    return;
  }

  const trigger = ( context.triggers || [] ).find(
    ( item ) => item.type === 'my-tab-return'
  );

  if ( ! trigger ) {
    return;
  }

  let leftAt = 0;
  let fired = false;

  document.addEventListener( 'visibilitychange', () => {
    if ( document.hidden ) {
      leftAt = Date.now();
      return;
    }

    const away = ( Date.now() - leftAt ) / 1000;

    if ( fired || ! leftAt || away < trigger.away ) {
      return;
    }

    if ( ! dialog.hasAttribute( 'data-modal-kit-ready' ) ) {
      return;
    }

    fired = true;
    dialog.dispatchEvent(
      new window.CustomEvent( 'modal-kit:request-open', {
        detail: { source: 'my-tab-return' },
      } )
    );
  } );
} );
```

Good to know

Each type can be added once per modal; the menu shows **Already added** for types the modal has.

The schema doesn’t allow unknown types or fields (`additionalProperties` is false), so without `modal_kit_meta_schema` the save is rejected.

A modal opened through `modal-kit:request-open` still goes through its display rules, such as frequency and devices.

Without `Settings`, a type of your own shows no settings under its name.

Applied in `modal-kit/src/editor/panels/triggers.js`.

Related

[`modal_kit_meta_schema`](https://modalkitwp.com/docs/hooks/modal_kit_meta_schema/)

[`modalKit.triggerMenuGroups`](https://modalkitwp.com/docs/hooks/modalkit-triggermenugroups/)

[`modal_kit_dialog_context`](https://modalkitwp.com/docs/hooks/modal_kit_dialog_context/)

## Need a hook that isn’t here?

[Ask us](https://modalkitwp.com/support/)

[Developers overview](https://modalkitwp.com/developers/)
