OpenCookies

Guides

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

  1. On WordPress, a banner only works if it loads before the tracking scripts (Analytics, Meta Pixel, videos…).
  2. Two routes: the OpenCookies plugin, which places it first and neutralizes known scripts, or a line of code added to the theme.
  3. In both cases, then run the test: tracking cookies should only appear after “Accept”.

The steps

  1. 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.

  2. 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.

  3. Option B: a line in the theme

    Without the plugin, add this to the functions.php file of a child theme. Priority 0 places the line before the other wp_head scripts:

    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.

  4. 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.

  5. 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.

Test my site

Sources

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.

← All guides · Cookie dictionary