Main content area

Integrating Cookie Control with the WP Consent API

The WP Consent API is a relatively new addition to WordPress, providing a standardized way for plugins and themes to interact with and manage user consent. With this plugin, all supporting plugins can use the same set of methods to read and register the current consent category, allowing consent management plugins and other plugins to work together, improving compliance with privacy laws.

You can download the latest version of the Cookie Control WP plugin here.

Why Integrate Cookie Control with the WP Consent API?

  1. Compatibility: By integrating with the WP Consent API, Cookie Control will work with other plugins that rely on the same API like Site Kit by Google, reducing potential conflicts.
  2. Future-proofing: As WordPress evolves, the WP Consent API is likely to become more deeply integrated into the core functionality. By adopting it early, we future-proof Cookie Control against upcoming changes.

How to use Cookie Control with Google Site Kit

Step 1: Install and Activate the Necessary Plugins

Install and activate the Cookie Control, WP Consent API, and Google Site Kit plugins on your WordPress site.

Step 2: Configure Google Site Kit

Set up Google Site Kit by following the plugin’s setup wizard.
Once set up, navigate to the admin settings of Site Kit and enable consent mode. This is crucial for integrating with Cookie Control and the WP Consent API.

Google Site Kit configuration page in Wordpress dashboard

Step 3: Configure Cookie Control Categories

In Cookie Control, create consent categories that group actions by type. When setting up these categories, consider the nature of the tracking or cookies involved. The WP Consent API categorizes consent into five key types:

  1. Functional
  2. Statistics (Anonymous)
  3. Statistics
  4. Preferences
  5. Marketing

To create a category, fill the form within Cookies tab containing the following properties:

nameA unique identifier for the category, will be used to store user preference. This value must be a valid cookie name, so special characters such as ()<>@,;:"?={}\/ are prohibited.
labelThe descriptive title assigned to the category and displayed to the user as a heading.
description A detailed explanation of the category, shown to users as a paragraph.
cookiesList the names of the cookies that should be protected based on user consent.

Step 4: Implement WP Consent API Functions in Callback Events

Utilize WP Consent API functions within the onAccept and onRevoke callback functions to handle user consent for Google Site Kit.

On Accept Callback Function

  • This function is triggered when a user opts into a specific cookie category. Replace 'statistics' with the appropriate category based on your setup.

    wp_set_consent('statistics', 'allow'); 

On Revoke Callback Function

  • This function is triggered when a user opts out of a specific cookie category. Again, replace 'statistics' with the appropriate category.

    wp_set_consent('statistics', 'deny'); 

By following these steps, Cookie Control will integrate smoothly with Google Site Kit through the WP Consent API, ensuring that user consent is managed consistently and effectively across your WordPress site. This integration not only enhances compliance with privacy laws but also improves the overall user experience.

You can download the latest version of the Cookie Control WP plugin here.

The product is under active development, so if you have any questions, suggested feature requests or simply want further information, contact us at info@civicuk.com.

For product terms, please review our Licence Agreement.