Hooks
modal_kit_theme_tokens
filter
Free
PHP
Change the values Native, Soft and Editorial take from the theme: surface, ink, radius, spacing, shadow and primary colour, plus the z-index.
Native (the default style), Soft and Editorial follow the active theme. Modal Kit reads the theme’s global styles and settings and prints them as --modal-kit-* custom properties in a :root rule, inline with the Modal block’s stylesheet, so the same values reach the site and the editor canvas.
The filter runs on init at priority 20. Two tokens reach further: primary and on-primary also give the fixed styles their Theme primary accent, and z sets the stacking order of every modal.
Parameters
Parameter
Description
$tokens
array
CSS values keyed by token name: surface and ink (the theme’s background and text colours), radius (its button radius), space (a middle spacing preset, used as the panel padding), shadow (a large shadow preset), z (the Stacking (z-index) value from Modal Kit → Settings → Display) and, when the palette has a primary colour, primary and on-primary. A value the theme doesn’t provide is empty.
Returns
array The tokens. Each value keeps only characters that can appear in a CSS value (no ;, :, { or }); empty values are dropped, and the stylesheet’s fallbacks apply.
Examples
Use other palette colours for the panel
Point the panel at other presets of your theme’s palette. Use slugs your theme defines.
add_filter( 'modal_kit_theme_tokens', function ( $tokens ) {
$tokens['surface'] = 'var(--wp--preset--color--base-2)';
$tokens['ink'] = 'var(--wp--preset--color--contrast)';
return $tokens;
} );
Choose the primary colour
Modal Kit takes the first of primary, accent-1, accent and secondary in the theme’s palette. Set on-primary with it: it is the text colour on that background, worked out for the original colour.
add_filter( 'modal_kit_theme_tokens', function ( $tokens ) {
$tokens['primary'] = 'var(--wp--preset--color--accent-2)';
$tokens['on-primary'] = 'var(--wp--preset--color--contrast)';
return $tokens;
} );
Good to know
Add the filter before init priority 20, at plugin load or on plugins_loaded.
Only the names above are read by the stylesheet. Names are printed as they are, as --modal-kit-{name}, so keep any you add to lowercase letters, digits and hyphens.
The tiles that preview the theme styles in the editor sidebar read the theme directly and don’t show filtered values; the canvas does.
Applied in modal-kit/includes/ThemeTokens.php.
Related