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 April 24, 2026

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:

Configuring geo-targeted privacy banners helps maintain compliance while delivering a smooth user experience. While the GDPR Cookie Consent plugin includes built-in support for major regulations, advanced setups—such as displaying a unified GDPR banner globally or limiting notices to specific US states—require custom code. By using PHP snippets to control consent behavior based on location, site owners gain greater flexibility, ensuring they remain adaptable, compliant, and user-focused as privacy laws evolve.