The ClearCrumb cookie consent JavaScript API gives your own code four calls and one event, so it can read the visitor’s choice, wait for consent and reopen the settings. This page also covers blocking your own scripts, the consent cookie, the PHP filters, the WP Consent API and the WP-CLI commands: everything you need to make your own code respect consent.
What does the cookie consent JavaScript API offer?
ClearCrumb puts a small object, window.ClearCrumb, on every page where the banner runs. It has four calls:
ClearCrumb.get(); // the saved choice, or null
ClearCrumb.has( 'statistics' ); // true once the visitor allowed that category
ClearCrumb.open(); // open the preferences dialog
ClearCrumb.show(); // show the banner again
Categories: necessary, preferences, statistics, marketing. necessary is always allowed.
ClearCrumb.get() returns null until the visitor has made a choice. After that it returns an object with the consent ID, the time of the choice (Unix seconds) and the categories:
{
id: '9f3c…e21a',
time: 1760104931,
categories: { necessary: true, preferences: false, statistics: true, marketing: false }
}
ClearCrumb.has() answers for what is in effect now. In regions where you chose opt-out, that can be true before any click, because the visitor has not objected. Use has() rather than reading get() when you decide whether to run code.
How does the cookie consent JavaScript API report changes?
Every time a visitor saves a choice, ClearCrumb fires the clearcrumb:consent event on document. Its detail is the same object ClearCrumb.get() returns.
document.addEventListener( 'clearcrumb:consent', function ( e ) {
if ( ClearCrumb.has( 'marketing' ) ) {
// load your marketing code
}
} );
In the cookie consent JavaScript API, the event only fires on a change. For a visitor who chose on an earlier page, check ClearCrumb.has() once when your script starts, and listen for the event as well. That covers both the returning visitor and the first click.
When a visitor takes a “yes” back, ClearCrumb reloads the page, because a script that already ran cannot be stopped. Your code does not need its own clean-up for that case.
For Google Tag Manager, ClearCrumb also pushes a clearcrumb_consent event to the dataLayer with a clearcrumb_categories object, so you can build triggers without custom code. Google’s own signals are covered in Google Consent Mode v2.

How do I block my own script until consent?
You often do not need the cookie consent JavaScript API at all. Mark the script tag instead, and ClearCrumb holds it until the visitor allows its category:
<script type="text/plain" data-cc-category="statistics" src="/my-stats.js"></script>
ClearCrumb releases it when the visitor allows statistics. Inline scripts work the same way: give them type="text/plain" and data-cc-category, and their code runs on consent. Released scripts run in page order, so a library and the code that uses it stay in sequence.
If the script needs a type of its own, such as module, put it in data-cc-type="module"; ClearCrumb restores it on release. For the 155 services ClearCrumb knows, you need none of this: they are blocked on the server automatically, as described in Block scripts until consent.
How is the choice stored?
The choice is stored in the first-party cookie clearcrumb_consent, for example 1.3.1760104931.9f3c…e21a.110: format version, banner revision, time, consent ID and one bit per optional category.
The bits follow the order preferences, statistics, marketing, so 110 means preferences and statistics allowed, marketing not. The cookie is set with SameSite=Lax, and with Secure on HTTPS sites. A cookie with an older banner revision counts as no choice, so the banner asks again.
Read consent through the cookie consent JavaScript API rather than parsing the cookie yourself. The calls stay stable even if the cookie format gains a new version.
Which shortcodes and blocks are there?
[clearcrumb_preferences]— a link that opens the preferences. Change its text withtext="…".[clearcrumb_cookie_policy]— the self-updating cookie policy.- Blocks: Cookie policy and Cookie settings link.
Any element with the class clearcrumb-open-preferences or the attribute data-clearcrumb-open also opens the preferences, which is often easier than calling ClearCrumb.open() from the cookie consent JavaScript API. Details are in the cookie policy shortcode guide.
Which PHP filters can I use?
| Filter | Use |
|---|---|
clearcrumb_block_page |
Return false to skip blocking on a request. |
clearcrumb_region |
Change the region decided for a visitor (eu, us or other). Receives the country code. |
clearcrumb_country |
Change the two-letter country code read from the server’s location headers. |
clearcrumb_cookie_domain |
Share the consent cookie with a parent domain. |
clearcrumb_layouts |
Register banner layouts. |
How long the consent log keeps records is a setting, not a filter: pick it under Keep consent records for on the Consent log screen; see GDPR consent log.
ClearCrumb also supports the WP Consent API: with the WP Consent API plugin active, wp_has_consent( 'statistics' ) works in your PHP and JavaScript and gives the same answer as the banner. ClearCrumb registers itself with it and reports the consent type for the visitor’s region. The WP Consent API plugin page explains the shared categories.

How do I use WP-CLI with ClearCrumb?
wp clearcrumb scan [--pages=<n>] [--format=table|json|csv]
wp clearcrumb log export [--days=<n>] [--format=csv|json]
wp clearcrumb scan reads up to 50 pages (home, shop pages, then the latest content) and lists the services and server-set cookies it finds, including the ones not on your services list yet. --pages sets how many pages to read; it defaults to 50.
wp clearcrumb log export prints the consent log as CSV or JSON, with time, consent ID, choices, region and country for each record. --days picks the last N days and defaults to 30. For example, wp clearcrumb log export --days=365 > consents.csv saves a year of records to a file.
Cookie consent JavaScript API: questions
When is the cookie consent JavaScript API available?
On every front-end page where the banner is switched on. Wrap your calls in a check such as if ( window.ClearCrumb ) so your code also works when the banner is off.
Can I open the banner from my own button?
Yes. Call ClearCrumb.show() for the banner or ClearCrumb.open() for the preferences dialog, or give the button the class clearcrumb-open-preferences.
Does ClearCrumb send consent anywhere else?
No. The choice stays in the visitor’s cookie and in your own database as the consent log, with the consent ID and IP address shortened and hashed. ClearCrumb helps you meet consent rules; it is not legal advice.