Install on WordPress
Put the CookieBeam banner on a WordPress site with the CookieBeam plugin or by adding the loader to your theme, and keep optimisation plugins away from it.
There are three ways to add CookieBeam to WordPress. Choose one and use only that one:
| Method | Use it when |
|---|---|
| The CookieBeam plugin | You have the plugin zip. It is the simplest way and handles optimisation plugins for you |
| Theme code | You maintain a child theme and want no extra plugin |
| Google Tag Manager | The site already loads tags through GTM and you cannot edit the theme |
Whichever you choose, create your banner, add the site's domain under Banner domains, and publish the banner to production first.
The CookieBeam plugin
The plugin isn't in the WordPress.org directory yet, so searching for it under Plugins → Add New Plugin won't find it, and there is no public download link. If you have the plugin zip from CookieBeam, install it by upload. Otherwise, use the theme method below.
The plugin needs WordPress 6.0 or newer and PHP 7.4 or newer.
- In WordPress, go to Plugins → Add New Plugin → Upload Plugin, upload the zip and activate the plugin.
- In CookieBeam, open the banner and go to Deployment → Install. Copy the banner ID, which is the UUID in the script URL.
- In WordPress, go to Settings → CookieBeam, paste the ID and save. You can paste the whole install snippet instead; the plugin takes the ID from it.
- Leave Environment empty on the live site.
- If you added the CookieBeam
<script>to the theme or a header-scripts plugin before, remove it.
The plugin prints the loader first in <head>, keeps WP Rocket, LiteSpeed Cache, Autoptimize, SiteGround Optimizer, Perfmatters and Cloudflare Rocket Loader from delaying it, adds shortcodes for your cookie declaration and a "Cookie settings" link, and passes the visitor's choice to the WP Consent API. See WordPress for all of its settings.
Add the loader to your theme
Use a child theme, so a theme update does not remove your change. Use one of these two options, not both.
Option 1: functions.php
Add this to your child theme's functions.php, with your own public Banner ID:
add_action('wp_head', function() {
echo '<script id="CookieBeam" src="https://cdn.cookiebeam.com/banner/PUBLIC_BANNER_ID/default/loader.js" type="text/javascript"></script>';
}, -1000);
Priority -1000 runs before normal head hooks, the same priority the plugin uses. It cannot run before a tracker that the theme hardcodes in header.php above wp_head(), or a hook with an earlier priority. Move those trackers below the loader, or use option 2.
Option 2: header.php
Copy header.php into your child theme and paste the loader directly after the opening <head> tag, before wp_head() and any hardcoded tracker:
<script id="CookieBeam" src="https://cdn.cookiebeam.com/banner/PUBLIC_BANNER_ID/default/loader.js" type="text/javascript"></script>
For both options: do not add async or defer, and add a "Cookie settings" link to your footer, for example <a href="#" data-cb="show-preferencesModal">Cookie settings</a>.
Optimisation and caching plugins
Full-page caching is fine, because the banner decides in the browser. Script optimisation is not: "delay JavaScript", "defer JavaScript", combining and minifying can move the loader behind the trackers it needs to hold back.
- With the plugin, the common optimisers are excluded for you.
- With the theme method, exclude
cdn.cookiebeam.comfrom every delay, defer, combine and minify feature yourself.
After any change, clear the page cache and the optimiser's cache, then check the HTML visitors receive.
WooCommerce and other plugins
- Plugins that read consent through the WP Consent API, such as WooCommerce and Site Kit, only learn the visitor's choice when the CookieBeam plugin is installed.
- Analytics, pixel and form plugins add their own scripts. Check what they load in a scan, and test the cart and checkout after rejecting optional categories.
Check it works
Log out, or use a private window: logged-in administrators often see a different set of scripts. Then follow Verify your installation.