Cookie consent for WordPress

The banner has to load before the tags your theme and plugins print, so it goes in wp_head with the highest priority.

Set it up with your AI agent

Connect the Croombit MCP server to your editor or coding agent and paste this. It creates the site, the cookie categories and the banner, and edits your code.

Using Croombit: create a site for this project with Analytics (ANALYTICS) and Advertising (MARKETING) cookie categories, off by default, publish them and publish the banner. Create a TEST publishable key for localhost:3000. This is a WordPress theme: print the cmp.js tag from functions.php on wp_head with priority 1, and change the analytics <script> tags in our templates to type="text/plain" with data-tc-consent.

The agent works in TEST. Going live takes two steps in the console: verify your domain and swap in a LIVE key — see going live.

Or by hand

1. Print the tag first in <head>

// In your (child) theme's functions.php, or a code-snippets plugin.
// Priority 1 prints it before the tags other plugins add to <head>.
add_action('wp_head', function () {
    echo '<script src="https://croombit.com/cmp.js" data-tc-api-key="pk_live_…"></script>';
}, 1);

2. Hold back trackers

Tags in your own templates: type="text/plain" plus data-tc-consent. Tags that other plugins print straight into the page are caught on a best-effort basis when they come from well-known hosts — for a guarantee, turn off the plugin's own snippet and add the tag yourself, tagged.

<script type="text/plain" data-tc-consent="analytics" async
        src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>
<script type="text/plain" data-tc-consent="analytics">
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXX');
</script>

Put these in a Custom HTML block — the list on your cookie policy page, the link in the footer:

<div data-tc-cookie-declaration></div>
<a href="#" data-tc-open-preferences>Cookie settings</a>

Questions

Does it work with page caching plugins?

Yes. The tag is the same for every visitor; the decision lives in the visitor's browser and in the vault, not in the cached HTML.