The official CookieBeam WordPress plugin is the recommended installation: it prints the synchronous loader early in the head and includes optimizer exclusions. If you need a manual installation, use one of the methods below.
First create and configure your banner, then publish it to production. Open Install and copy the production loader containing your public Banner ID. Replace PUBLIC_BANNER_ID in the examples below with that ID. Choose exactly one installation method per page; do not combine a direct loader, the plugin, and a GTM consent tag. See the publishing sequence and canonical script-tag instructions.
Why skip the plugin?
A manual installation can suit a site where a developer already maintains the child theme and script order. It also makes that developer responsible for preserving the loader across theme changes and configuring optimizer exclusions.
- Performance. Measure the loader and subsequent banner assets on your own pages; payload size and timing depend on configuration and caching.
- Caching conflicts. Check the final cached HTML after changing a theme or optimization setting. A cache or script optimizer can move or delay the loader.
- Updates. A child theme protects custom code from parent-theme replacement, but theme and WordPress changes still need testing.
- Consent records. Review consent records in CookieBeam rather than adding a separate WordPress storage mechanism.
The external script still needs correct placement and consent rules. Removing a plugin alone does not establish working consent enforcement.
Method 1: Add the script to header.php
Insert the loader immediately after the opening <head>, before wp_head() and any hardcoded tracker. Theme updates can overwrite this change; use a child theme.
<script id="CookieBeam" src="https://cdn.cookiebeam.com/banner/PUBLIC_BANNER_ID/default/loader.js" type="text/javascript"></script>Method 2: Add via functions.php
Add this to your child theme’s functions.php. Do not also add the header.php snippet:
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, matching the official integration’s default priority. It cannot run before a tracker hardcoded before wp_head(), or a hook with an earlier priority. Move those trackers after the loader or use Method 1 to place the loader before them.
Inspect the rendered HTML: the loader must be near the start of <head>, before Google tags and other managed scripts. Do not add async or defer. Exclude the loader from delay, defer, and script-reordering optimizations.
Method 3: Google Tag Manager
If your WordPress site already uses GTM, use the CookieBeam Consent Mode template from the Community Template Gallery as an alternative to direct installation.
- In your GTM web container, open Templates → Tag Templates → Search Gallery and search for CookieBeam.
- Select CookieBeam Consent Mode, review its permissions, and click Add to workspace.
- Open Tags → New → Tag Configuration, select that template, and enter the public Banner ID from your published banner’s Install page.
- Choose Consent Initialization – All Pages as the trigger and save.
- Configure consent settings for downstream tags. Use GTM Preview to test a fresh session, acceptance, rejection, and withdrawal, then submit and publish the container.
Use only one CookieBeam installation per page. Remove the direct loader or plugin injection when choosing this method. Consent Mode can allow cookieless requests while consent is denied; configure downstream tags and keep hardcoded non-essential scripts outside GTM inert as needed. Follow the canonical GTM instructions and script-blocking guide.
WooCommerce considerations
Test the store as well as its content pages:
- Checkout pages. Review each payment service’s cookies and purpose. Do not classify every cookie from a payment provider as necessary. Confirm optional analytics and advertising follow the visitor’s choices on checkout and thank-you pages.
- Regional rules. Configure and publish the regional consent rules appropriate to your visitors, then test their behavior. Geolocation does not replace that review.
- Cart fragments. Check that cart updates such as
wc-ajax=get_refreshed_fragmentsstill work when optional categories are rejected. - Cart and session cookies. Inspect cookies such as
woocommerce_cart_hashandwoocommerce_items_in_cart, document their purpose, and verify that the rules preserve necessary cart functionality.
Measure performance on your site
Compare the same pages before and after installation under the same network and cache conditions. Include a content page, product page, cart, and checkout. Inspect the loader and subsequent banner asset requests in DevTools and measure LCP, INP, and CLS.
The loader must run synchronously before managed tags. Do not add async or defer to improve a score. Check that optimization and caching settings preserve its position and test consent behavior again after any change.
Keep the loader synchronous
Place the loader once near the start of <head>, before Google tags and other managed scripts. Do not add async or defer, and exclude it from script-delay optimizers. A wp_head hook cannot run before markup emitted ahead of that hook.
For hardcoded non-essential scripts, use type="text/plain" data-category="analytics" (or the appropriate category), with data-src for external URLs. Dynamically inserted scripts can be blocked using the scan-derived script map; verify coverage before publishing.
Testing your setup
After publishing the banner and deploying the site change, verify the rendered pages:
- Check cached HTML. Use your normal cache-refresh process after changing the template. Inspect the HTML that visitors receive and confirm there is one installation.
- Check ordering. For direct installation, confirm the public Banner ID loader is early in the head, before managed tags, without async or defer.
- Test a fresh session. Open a private window with storage cleared and inspect the console, cookies, and network requests before making a choice.
- Test rejection and acceptance separately. Confirm non-essential services remain blocked when rejected and the expected services become available after acceptance.
- Test persistence and withdrawal. Reload after choosing, reopen preferences, change the choice, and check the stored state and requests again.
- Check integrations and store pages. Use Tag Assistant for Google consent states; exercise mobile layouts, cart, checkout, and thank-you pages.
Common questions
Does this work with page builders like Elementor or Divi?
Check the HTML generated by your theme and builder. The direct loader must appear once near the start of the head before managed tags on every relevant template.
What about multisite installations?
Install through each site’s active child theme, or have your developer manage a shared integration. Verify each domain’s published banner ID and script order separately.
Will this conflict with my existing cookie plugin?
Plan the replacement so each page uses one consent installation. Test the replacement and remove the old injection when switching; two banners can create conflicting states.
Do I need to change anything for regional consent?
Review, configure, and publish your regional rules in the dashboard, then test the relevant visitor experiences. Do not assume the loader alone selects the settings your site needs.
What if I want to customize the banner design?
Edit colors, text, position, button labels, and regional rules in the dashboard. Save and republish the banner to update the live configuration, then verify it on your site.