Black Friday
  • Days
  • Hrs
  • Mins
  • Secs
30% Off

Use coupon code 'DEC30' Limited Offer!!

Star

Home > Docs > Code Snippets for Geo-Targeting GDPR and US State Law Privacy Banners

Code Snippets for Geo-Targeting GDPR and US State Law Privacy Banners

Last updated on November 7, 2025

The GDPR Cookie Consent plugin provides flexible consent management for websites targeting global audiences. Although it supports GDPR and US State Laws (such as CCPA/CPRA), some site owners prefer a single banner worldwide without the “Do Not Sell My Personal Information” option from CCPA.

This article explains how to configure the plugin to:

  • Show the GDPR-style banner for all visitors, regardless of location.
  • Set different consent defaults for US visitors versus EU/EEA visitors.
  • Disable the CCPA banner and “Do Not Sell” checkbox.

Currently, this use case cannot be configured purely via the plugin’s UI. Instead, you can add a custom function to override cookie behavior depending on the visitor’s IP-based location.

To implement this:

  1. Open your child theme’s functions.php file.
  2. Add the following PHP snippet:

By adding this snippet, you will:

  • Display the GDPR banner globally by selecting Worldwide in the Geo Targeting settings.
  • Enable scripts to run by default for US visitors. If a visitor rejects consent, the scripts will then be blocked.
  • Block scripts by default for visitors outside the US, ensuring they only run after explicit consent is given.

The GDPR Cookie Consent plugin supports geo-targeting, allowing you to display different cookie banners based on a visitor’s location. Store owners may prefer to comply only with US states where cookie consent notices are legally required (such as California or Colorado), while hiding the banner in other states.

To implement this:

  1. Open your child theme’s functions.php file (never edit the parent theme directly).
  2. Add the following PHP snippet: