For developers
JavaScript, events, shortcodes and filters for themes and plugins that work with XT Cookie Consent.
In the browser
window.XTCC.open()opens the cookie choices panel.window.XTCC.get()returns{ analytics, marketing }, ornullbefore a choice is made.- The
xtcc:consentevent fires ondocument, with the same details, whenever consent is applied. <html data-xtcc-consent="analytics marketing">reflects the current choice, for CSS.- Any element with
data-xtcc-open, or any link to#cookie-settings, opens the cookie choices.
document.addEventListener('xtcc:consent', (event) => {
if (event.detail.analytics) {
// start something that needs analytics consent
}
});Holding your own scripts
Give a script type="text/plain" and a category, and it runs once that category is allowed:
<script type="text/plain" data-xtcc="analytics">
// runs after analytics is allowed
</script>Use data-xtcc="marketing" for marketing scripts.
Shortcodes and template tags
[xt_cookie_table]: the cookie list, for your cookie or privacy policy.[xt_cookie_settings]: a Cookie settings link.<?php echo xtcc_settings_link(); ?>: the same link, in a theme.
Filters
xtcc_services: add to the services list. A service'shandlesare held until its category is allowed.xtcc_detected: what was found on the site, as service key ⇒ description.xtcc_held_handles: script handles to hold.xtcc_embed_providers: which embedded content is held, and who it comes from.xtcc_hold_embeds: returnfalseto leave embeds alone on a request.xtcc_youtube_nocookie: returnfalseto keep YouTube embeds on youtube.com.xtcc_wpforms_cookie_off: returnfalseto leave WPForms' visitor cookie on (its User Journey add-on needs it).xtcc_config: everything the banner and panel show, before it's printed, so a translation plugin can swap the texts.xtcc_active: turn the banner off for certain requests.
The consent cookie
The choice is stored in the first-party xtcc_consent cookie as { v, t, a, m, i }: the settings version, the time, analytics, marketing and the consent ID.
Notes
- Elementor's video widget builds its player in the browser, so turn on its own Privacy mode rather than relying on the YouTube switch.
- Withdrawing consent clears that category's cookies and reloads the page, since scripts that already ran can't be unloaded.