How to add a cookie banner to WordPress (the right way)

Short answer
To add a cookie banner to WordPress, load the consent script before any tracking code, usually as the first item in the head. Then make sure analytics and ad tags wait for consent, set Google Consent Mode defaults to denied, and test in a private window that nothing fires before a visitor chooses.
Key takeaways
- The banner script must load before Google Analytics, the Meta Pixel and other tags.
- A banner that shows a message but lets trackers run is not consent.
- Test in a private window with the browser's developer tools open.
- Keep a record of each choice in case a regulator or client asks.
Most WordPress sites already have a cookie banner. Many of them do not actually do anything: the message appears, but Google Analytics, the Meta Pixel and other tags have already loaded in the background. This guide shows how to set up a banner that holds trackers until the visitor chooses.
What a cookie banner on WordPress needs to do
A working banner has four jobs:
- Ask before tracking where the law requires it, such as Quebec and the EU.
- Hold scripts that set non-essential cookies until their category is allowed.
- Tell Google tags the visitor’s choice through Consent Mode v2.
- Keep proof of what each visitor chose and when.
If your current banner only does the first part, the site is still collecting data without consent.
Where the script goes
Order matters. The consent script needs to run before any tag that sets cookies. In WordPress, that means the very top of the <head>, above Site Kit, MonsterInsights, a pixel plugin or a Google Tag Manager container.
You have three common options:
- Your theme’s header.php, right after the opening head tag. Simple, but a theme update can remove it if you edit a parent theme.
- A small plugin or code snippet hooked to
wp_headwith priority 0 or 1 so it prints first. - Google Tag Manager, using the Consent Initialization trigger. See our Google Tag Manager guide.
Step by step
- Create your account and add the site. Sign up, add your domain and let the scanner list the cookies and trackers it finds.
- Copy your one line of code. The install tab shows a script tag with your site key.
- Paste it at the top of the head. Use header.php, a snippet hooked to wp_head at priority 0, or Google Tag Manager with the Consent Initialization trigger.
- Choose your rules and look. Pick opt-in for Quebec and the EU, set your colours and check the English and French text.
- Test before and after a choice. In a private window, confirm that no analytics or ad cookies exist until you click Accept.
How to hold trackers until consent
There are two ways scripts get held. North Consent recognises common trackers such as the Meta Pixel, TikTok, LinkedIn Insight, Hotjar and Microsoft Clarity and keeps them from running until their category is allowed. For anything else, you can mark the script so it waits:
<script type="text/plain" data-nc-category="marketing">
// your tag here
</script>
Google tags are different. They load, but Consent Mode tells them not to set ad or analytics cookies until consent is given. Read the Consent Mode v2 setup guide for the details.
Caching and page builders
WP Rocket, LiteSpeed Cache and host-level caching are fine as long as the banner decides the region in the browser, not on the server. Otherwise a cached page built for one visitor can show the wrong banner to the next. If you use a script optimizer that delays JavaScript, exclude the consent script so it is never delayed.
How to test it
Open the site in a private window, open the developer tools, and look at the Application tab under Cookies before you click anything. You should see only essential cookies. Then reject, reload and check again. Finally accept and confirm the analytics cookies appear. Our cookie audit guide walks through this in more detail.
Frequently asked questions
Do I need a plugin for a cookie banner on WordPress?
No. A hosted banner works with one script tag in the head. A plugin can be convenient for placing that tag, but the banner itself does not need to run inside WordPress.
Will a cookie banner slow down my WordPress site?
A well built banner script is small and loads once. Keeping trackers on hold until consent often makes the first page load lighter, not heavier.
Does the banner work with WooCommerce?
Yes. Cart and session cookies are essential and keep working. Marketing pixels on the checkout wait for consent like any other page.
Keep reading
Quebec Law 25 and cookies: what your website needs to do
What Quebec's Law 25 means for cookies on your website: off by default, clear information, an easy way to choose, and proof. A practical checklist.
Google Consent Mode v2: a plain-language setup guide
Set up Google Consent Mode v2 correctly: the four consent signals, default denied, basic vs advanced mode, and how to check it works with Tag Assistant.
How to audit the cookies on your website
A practical cookie audit: find every cookie and tracker on your site, sort them into categories, check what fires before consent, and keep the list current.