Platforms

How to add a cookie consent banner to WordPress

Paste the Cookiequiet snippet in the site header, before any analytics or marketing tag: with the free WPCode plugin under Code Snippets, then Header & Footer, or in a child theme with the wp_head hook at priority 0. Mark the tags you paste yourself with type="text/plain" and a data-cq-category, deactivate any other consent plugin, and add a Cookie preferences link to the footer menu.
Published 20 October 2026 · By the Cookiequiet team · Markdown

Steps

Copy your snippetIn the Cookiequiet dashboard, open your website and copy the install snippet. It is one script tag with your site key, data-consent-mode and data-auto-block set to 1, and the defer attribute.
Paste it in the header with WPCodeInstall and activate WPCode, go to Code Snippets, then Header & Footer, paste the snippet at the top of the Header box and click Save Changes. The Header box prints inside the head of every page, in classic and block themes alike.
Or print it from a child themeIf you prefer code, add an add_action call on wp_head with priority 0 to your child theme's functions.php that echoes the snippet. Priority 0 runs before the tags other plugins hook on wp_head.
Mark the tags you pasted yourselfFor every Google Analytics, Meta Pixel or Hotjar block you added in a snippet, change the opening script tag to type="text/plain" with data-cq-category set to analytics or marketing. Do the same for both the external and the inline script of the Google tag.
Switch on consent mode in Site KitIf Site Kit by Google prints your Google tag, turn on consent mode in Site Kit, then Settings, then Admin Settings, so Google's default consent state is printed before the tag. Cookiequiet sends the update when the visitor chooses.
Deactivate other consent plugins and caching rulesDeactivate Complianz, CookieYes, Cookie Notice or any other banner plugin so visitors see one banner. Exclude cq.js from script delay features such as WP Rocket's Delay JavaScript execution, then purge the cache.
Add the Cookie preferences linkIn Appearance, then Menus (or the footer navigation block in the Site Editor), add a custom link with the URL #cq-preferences and the label Cookie preferences. Cookiequiet opens the preferences centre when it is clicked.
Test with Reject allOpen the site in a private window, click Reject all and check the browser's cookie list: no _ga, _gid or _fbp should be present. Accept all, reload and confirm the tags now load. Both choices appear in the consent log.

Where to paste the snippet in WordPress

The snippet must print inside <head> on every page, above every analytics or marketing tag. There are two reliable ways to do that on WordPress.

With WPCode (no code). Install the free WPCode plugin, then go to Code Snippets, then Header & Footer. Paste the snippet at the top of the Header box and click Save Changes. WPCode prints the Header box inside the head of every page, and it works with classic themes and block themes such as Twenty Twenty-Five.

html
<script src="https://cookiequiet.com/cq.js" data-site="YOUR_SITE_KEY" data-consent-mode="1" data-auto-block="1" defer></script>

With a child theme or a small plugin. The wp_head action fires inside the head of the theme. Hook it at priority 0 so the snippet prints before the tags that other plugins add at the default priority of 10:

php
add_action( 'wp_head', function () {
echo '<script src="https://cookiequiet.com/cq.js" data-site="YOUR_SITE_KEY" data-consent-mode="1" data-auto-block="1" defer></script>';
}, 0 );

Do not edit the parent theme's header.php: the next theme update would remove the line. Whichever method you use, purge your page cache afterwards.

How to handle the tags your plugins add

WordPress sites rarely paste tags by hand; plugins do it. Three cases:

  • Google tag printed by Site Kit. Site Kit prints the Google tag itself, so you cannot mark it. Turn on consent mode in Site Kit, then Settings, then Admin Settings: Site Kit then prints Google's default consent state (denied for visitors in the EEA, the UK and Switzerland) before its tag. Cookiequiet sends the consent update command when the visitor chooses, which the Google tag applies whatever printed the tag. Site Kit asks you not to enable the consent mode feature of another consent plugin at the same time; Cookiequiet has none to enable, so there is no conflict. The Google Analytics 4 guide explains what the tag does while consent is denied.
  • Tags you pasted in a snippet. Mark them. For the Google tag, both script tags change:
html
<script type="text/plain" data-cq-category="analytics" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script type="text/plain" data-cq-category="analytics">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>

The Meta Pixel base code gets data-cq-category="marketing". Tags marked with data-cookiecategory or data-cookieconsent from CookieYes or Cookiebot keep working; see switching from CookieYes.

  • Chat widgets and pixels loaded by their own plugin. Most of them insert their script with JavaScript. With data-auto-block="1", Cookiequiet holds the scripts and iframes of about 80 known trackers (Hotjar, Clarity, Meta, TikTok, LinkedIn, HubSpot and others) created this way until their category is granted. A tracker that a plugin prints as plain HTML before our snippet runs before we can stop it: move it below the snippet or mark it.

YouTube embeds from the block editor are printed as plain iframes, so they load at once. To make a video wait for consent, use a Custom HTML block with data-cq-src instead of src, as explained in YouTube embeds and consent.

Visitors must be able to change their mind as easily as they consented. Cookiequiet opens the preferences centre from any link whose URL is #cq-preferences, and from any element carrying data-cq-show-preferences.

  • Classic themes: Appearance, then Menus, add a Custom Link with URL #cq-preferences and label "Cookie preferences" to the footer menu.
  • Block themes: Appearance, then Editor, open the footer template part, select the Navigation block and add a link with the same URL.

If you cannot edit the footer, the banner settings offer a small floating "Cookie preferences" button shown after a choice.

How to test the installation

  1. Open the site in a private window. The banner shows with Accept all and Reject all of the same size.
  2. Click Reject all. In the browser's developer tools (Application, then Cookies in Chrome), only cq_consent and WordPress's own cookies should be present: no _ga, _gid, _fbp or _hjSession.
  3. Clear the cookies, reload, click Accept all: the marked scripts run and their cookies appear.
  4. Open the consent log in the dashboard: both choices are recorded with date, categories and country.

If the banner does not show, check that the snippet is in the page source (View source, search for cq.js), that the cache was purged, and that geo-targeting is set to everywhere while you test from an unregulated country.

What is specific to WordPress

  • Two banners. Any other consent plugin (Complianz, CookieYes, Cookie Notice, GDPR Cookie Compliance, Cookiebot's plugin) shows its own banner and may block or rewrite tags. Deactivate it after the switch; see switching from Cookiebot.
  • Optimization plugins. Script delay and aggregation features (WP Rocket's Delay JavaScript execution, LiteSpeed Cache, Autoptimize) can move cq.js after the tags it must precede. Add cq.js to the exclusion list of such features.
  • WooCommerce. Its cart and session cookies are strictly necessary: they need no consent, and the scanner lists them under Necessary in the cookie table. A shop that also runs analytics or marketing tags still needs the banner for those tags.
  • Multisite. Each site of the network needs its own site key, so the consent log and the policies stay separate.

The free cookie scanner shows which tags your plugins actually print, which is the quickest way to find the ones to mark.

Questions

No. The snippet is one script tag; WPCode's Header & Footer box is simply the easiest place to paste it without touching theme files. A child theme with the wp_head hook does the same job.
Yes. Both WPCode's Header box and the wp_head hook print inside the head of block themes, and the Cookie preferences link goes in the footer's Navigation block in the Site Editor.
Keep only one banner plugin active. Two banners confuse visitors and each one records a different consent. Cookiequiet understands the data-cookiecategory and data-cookieconsent markup, so the tags you marked for the old plugin keep working after you deactivate it.
Turn on consent mode in Site Kit's Admin Settings. Site Kit then prints Google's default consent state as denied for EEA, UK and Swiss visitors before the Google tag, and Cookiequiet sends the update when the visitor accepts or rejects analytics. Google Analytics sets its _ga cookie only after analytics_storage is granted.
Usually a cached page without the snippet, or a script delay feature that moved cq.js. Purge the cache, exclude cq.js from delay and aggregation features, and check the page source for cq.js.

Put a quiet banner on your website today

Free for one website with every core feature, no card and no trial clock. Upgrade a website to Pro for $3 a month when you want the AI designer, no branding and the five-year consent log.