Hooks
modal_kit_link_prefix
filter
Free
PHP
Change the prefix of modal anchor links and dialog ids, which Modal Kit → Settings → General sets to modal- by default.
A link to #modal-autumn-sale opens the modal whose slug is autumn-sale, and the same string is that <dialog>’s id. The part before the slug is the Link prefix from Modal Kit → Settings → General, modal- by default; this filter changes it in code.
The prefix is read wherever links and ids are made: when Modal Kit looks for the modals a page links to, for each dialog’s id, in the runtime’s settings, and for the link shown in the editor’s Triggers panel.
Parameters
Parameter
Description
$prefix
string
The Link prefix setting: lowercase letters, digits and hyphens, modal- by default. It can be empty.
Returns
string The prefix, cast to a string and passed through sanitize_html_class().
Example
Keep links from your old popup plugin working
Give each modal the slug the old popup had, and links to #popup-{slug} already in your content open it.
add_filter( 'modal_kit_link_prefix', function () {
return 'popup-';
} );
Good to know
Only letters, digits, hyphens and underscores survive sanitize_html_class(). An empty prefix is allowed: links become #autumn-sale, which can clash with heading anchors.
Links already in your content keep the old prefix, so changing it breaks them. ?modal=slug links don’t use the prefix and keep working while that link format is on.
The field on Modal Kit → Settings → General and its example still show the saved value; the anchor in the editor’s Triggers panel shows the filtered one.
It is read many times per request: keep the callback cheap and return the same value each time.
Applied in modal-kit/includes/Render.php.