Kjeks Scripting — gate scripts by handle
Map any registered script handle to a consent category. Kjeks holds the tag back until the visitor consents — you change nothing about the script itself.
101 Setup
This add-on gates already-enqueued scripts through Kjeks. Install the core plugin first — it provides the consent UI, the script gate, and the shared add-on base classes this plugin builds on.
Install & activate
-
Download the latest
kjeks-scripting.zipand upload it under Plugins → Add New → Upload Plugin, then activate it (network-activate on multisite). - Updates arrive automatically from GitHub releases.
Find a script handle
A handle is the first argument to wp_enqueue_script() /
wp_register_script(). View source and read the id
attribute of the script tag — WordPress appends -js:
<!-- View source. WordPress appends "-js" to the handle: -->
<script src="..." id="google-analytics-js"></script>
<!-- ^^^^^^^^^^^^^^^^ handle = "google-analytics" -->
Map handles to categories
Open Cookie Consent → Scripting (slug kjeks-scripting, mounted
as a submenu of the core Kjeks menu on both single-site and Multisite). Map each
script handle to a consent category (preferences,
analytics, or marketing) and save.
201 How gating works
On the front end each mapped handle is registered with the core Kjeks blocking registry, which rewrites the tag to a consent-aware, inert form until the visitor consents to the mapped category. You write no output and touch none of the scripts:
// On the front end each mapped handle is registered with the core
// Kjeks blocking registry, which rewrites the tag to an inert form:
kjeks_register_integration( 'scripting-google-analytics', array(
'category' => 'analytics', // the mapped category
'label' => 'google-analytics', // the handle
'handles' => array( 'google-analytics' ),
) );
The gated markup is identical for every visitor, so it stays cache-friendly;
consent is released client-side on the kjeks:granted event.
marketing, so a bad mapping
can never leave a script ungated.
301 Config & internals
Option
| Option | Scope |
|---|---|
kjeks_scripting | Network option on Multisite, regular option on single site — a category per script handle. |
Built on AddonKit
Kjeks Scripting is the reference example for the shared
Soderlind\Kjeks\AddonKit base classes: it extends
AddonKit\Plugin and AddonKit\SettingsPage, stores its
option through AddonKit\Options, and renders the category picker with
AddonKit\Categories. See the
Build an add-on guide to build your own the
same way.