How to Add Cookie Banner on WordPress Website

If your WordPress website uses cookies or tracking technologies (e.g., Google Analytics, Google Search Console), you must ask users for consent before storing cookies, especially to comply with GDPR and other privacy laws.

In this tutorial, you’ll learn how to manually install the Consentise Cookie Banner on your WordPress site without the need for additional plugins.

  1. Go to the Consentise Script Generator.
  2. Enter the following:
    • Your website domain (e.g., www.example.com)
    • Privacy Policy URL (e.g., https://www.example.com/privacy-policy)
    • Default Language (e.g., en)
  3. Click Generate Script to receive two code snippets:
    • Mandatory Script (must go into <head>)
    • Consent Banner Script (must go into <body>)

Step 2: Add the Mandatory Script to the <head>

To add this script to your WordPress <head> section:

  1. In your WordPress dashboard, go to AppearanceTheme File Editor.
  2. Select header.php from the list of theme files on the right.
  3. Paste the Mandatory Script before any other tracking codes, just before the closing </head> tag:
<script>
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('set', 'url_passthrough', true);
gtag('set', 'ads_data_redaction', true);
gtag('consent', 'default', {
  'ad_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'analytics_storage': 'denied'
});
// UET default settings
window.uetq = window.uetq || [];
window.uetq.push('consent', 'default', {
  'ad_storage': 'denied'
});
</script>

Tip: If you’re using a child theme, edit header.php in the child theme to preserve changes during theme updates.

To display the banner, add the second script after the Mandatory Script, inside the <body>. You can do this in a few ways, but here’s the manual method:

  1. In the same Theme File Editor, open footer.php.
  2. Paste the banner script before the closing </body> tag:
<script src="https://www.consentise.com/v1.2/consent-min.js" 
data-cookiedomain="www.website.com" 
data-privacy-policy-url="https://www.website.com/privacy-policy" 
data-preferred-color="#4fa5d3"
data-banner-position="bottom"
data-default-language="en"
defer></script>

Replace the domain and privacy policy values with your own site details.

Step 4: Save & Test

After saving changes:

  1. Open your site in a private/incognito window.
  2. Confirm that:
    • The cookie banner is shown.
    • No trackers are fired before consent is given.
    • Consent preferences are respected and stored.

Use developer tools or browser extensions like Tag Assistant to verify proper behavior.

Optional: Use a Custom Code Plugin

If you prefer not to edit theme files, you can use a plugin like Insert Headers and Footers or Code Snippets to add both scripts:

  • Add the Mandatory Script to the “Header” section.
  • Add the Consent Banner Script to the “Footer” section.

By following these steps, your WordPress website will be GDPR-compliant and protect user privacy using the lightweight and customizable Consentise banner.