Cookie banner on WordPress: how to set it up correctly
By the OpenCookies team · published October 22, 2026 · updated October 22, 2026
The essentials in 3 lines
- On WordPress, a banner only works if it loads before the tracking scripts (Analytics, Meta Pixel, videos…).
- Two routes: the OpenCookies plugin, which places it first and neutralizes known scripts, or a line of code added to the theme.
- In both cases, then run the test: tracking cookies should only appear after “Accept”.
The steps
- Create your banner
Create a free account on OpenCookies, add your site address and get your key. You can set texts and colors with a live preview.
- Option A: the WordPress plugin
The OpenCookies plugin places the banner first in the head and neutralizes known tracking scripts before the choice. Install it, paste your key, and you are done.
- Option B: a line in the theme
Without the plugin, add this to the
functions.phpfile of a child theme. Priority0places the line before the otherwp_headscripts:add_action('wp_head', function () { echo '<script src="https://opencookies.com/banner/oc.js" data-site="KEY"></script>' . "\n"; }, 0);Use a child theme, otherwise the line disappears at the next theme update.
- Watch your other plugins
Plugins that add their own scripts (statistics, advertising pixels, embedded videos, widgets) can load trackers. The OpenCookies plugin marks the most common ones. For the others, the test report tells you which ones cause problems.
- Clear the cache
After installing, clear your site cache (cache plugin, CDN): otherwise visitors may receive an old version of the page, without the banner.
Check it with the OpenCookies test
Run the OpenCookies test on your site. The report shows the cookies and requests at three moments: before any choice, after “Refuse”, after “Accept”.
Before any choice and after “Refuse”, only technical cookies should remain. If a measurement or advertising cookie is present, the report shows where it comes from.
Sources
- WordPress — wp_head hook
- EDPB — Guidelines 05/2020 on consent
- Google — Set up consent mode on websites
This guide describes a technical approach, not legal advice.
Frequently asked questions
Does the plugin slow down my site?
The banner is a single small script. The biggest effect on speed generally comes from the tracking scripts themselves, which the banner prevents from loading before consent.
Do I need a child theme?
Only for option B (line of code). With the plugin, nothing to change in the theme.