Home > Docs > GDPR Cookie Consent > How to add custom script blocker using GDPR Cookie consent plugin

How to add custom script blocker using GDPR Cookie consent plugin

Last updated on May 8, 2023

Script Blocking is of vital importance when it comes to GDPR Cookie compliance. The premium version of the GDPR Cookie Consent plugin has the capability to automatically block the active scripts that inject cookies on the website until the users give their explicit consent. The inbuilt script blocker in this plugin is capable of blocking cookies from the following third-party scripts:

GDPR Cookie consent-Manage Script blocker
GDPR Cookie consent-Manage Script blocker

Blocking Custom Scripts

Apart from the above-listed pre-defined scripts, the GDPR Cookie consent plugin also allows adding a custom script blocker extension whereby the user can explicitly block scripts of their choice.

To achieve this simply add the below code snippet to the active child theme functions.php.

The above code snippet inserts two new script blockers from Google Translator and Recaptcha. Likewise, you can insert scripts accordingly by entering appropriate values for the array fields id, label, key, category, and status.

  • id: Key in the name of the script.
  • label: Enter an appropriate label name for the script blocker that will appear in the interface.
  • key: Specify any number of unique strings separated with commas that can be used to identify your script(an array of strings).
  • category: The plugin maintains necessary and non-necessary as two default categories. Assign the category slug of an existing category for the script. If such a category does not exist then create a new cookie category and assign its slug.
    Note: Ensure that the correct slug (lower case) of the corresponding category is placed in the code snippet.
  • status: Set the status as ‘yes’ to make it active by default else set it as ‘no’.

On inserting the above code snippet to the function.php file, the script blocker interface will be as shown below:

GDPR Cookie consent-Adding custom script blocker
GDPR Cookie consent-Adding custom script blocker

Two new additional script blockers namely Google Translator and Recaptcha are appended along with the existing service script blockers.

Refer How to Automatically Block Cookies Using the GDPR Cookie Consent Plugin to know more on it.