The "Callbacks" field on the Customization tab of the Cookie Consent kit holds a JavaScript object of TermsFeed Free Cookie Consent 4.2.0 callbacks, which TermsFeed AutoTerms prints on every page. Use it to send Google Consent Mode v2 updates or to start code once the visitor accepts a category. The plugin prints the object as you wrote it, in a <script> of its own with the id termsfeed-autoterms-cookie-consent-callbacks, so a syntax error there drops only the callbacks.

The keys are the callback names of the Cookie Consent script, each with a function as its value. Look up each callback, its arguments, and the moment it fires in Free Cookie Consent Callbacks and DOM Events.

Make the Google Consent Mode v2 default command the first script in the <head> of every page, above any Google tag, any Google Tag Manager container, and the Cookie Consent script. The plugin does not print Consent Mode defaults, and the Callbacks send only updates. WordPress prints the cookie-consent.js tag of the kit at priority 9 of the wp_head action, so add the defaults from a wp_head action with priority 1.

Paste this code into a code snippets plugin or the functions.php file of a child theme. It prints the denied default of all 6 signals.

add_action( 'wp_head', function () {
    ?>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('consent', 'default', {
        'ad_storage': 'denied',
        'ad_user_data': 'denied',
        'ad_personalization': 'denied',
        'analytics_storage': 'denied',
        'functionality_storage': 'denied',
        'personalization_storage': 'denied',
        'wait_for_update': 500
      });
    </script>
    <?php
}, 1 );

Check the order in the page source: the gtag('consent', 'default', ...) call is the first script in the <head>, above cookie-consent.js from www.termsfeed.com, any Google tag, and any Google Tag Manager container. Copy the default command and the full page layout from Step 1: Set every consent signal to denied before any Google tag.

Send Google Consent Mode v2 updates from a user_consent_saved callback, which sends granted or denied for every category on each answer, so a withdrawal reaches the Google tags at once. Each update reaches them before the Cookie Consent script releases any vendor script. The typeof gtag check keeps the code silent on a page without the Google tag.

{
    'user_consent_saved': function (details) {
        if (typeof gtag !== 'function') {
            return;
        }
        gtag('consent', 'update', {
            'analytics_storage': details.tracking ? 'granted' : 'denied',
            'ad_storage': details.targeting ? 'granted' : 'denied',
            'ad_user_data': details.targeting ? 'granted' : 'denied',
            'ad_personalization': details.targeting ? 'granted' : 'denied',
            'functionality_storage': details.functionality ? 'granted' : 'denied',
            'personalization_storage': details.functionality ? 'granted' : 'denied'
        });
    }
}

On later page loads of a visitor who answered, the callback runs only while the Configuration Parameters set user_consent_saved_on_page_load to true. Without that key, Google tags on those pages keep the denied default. Read when the callback runs in Free Cookie Consent Callbacks and DOM Events.

Replace, save, and check your Callbacks on your WordPress website.

  1. Open the Customization tab of the Cookie Consent kit and replace the content of the "Callbacks" field with your object.
  2. Click the "Save Changes" button. The plugin checks the code first, without running it, and asks before saving code with a syntax error.
  3. Open the "Configuration Parameters" tab, add "user_consent_saved_on_page_load": true, as a new line after the opening { of the JSON, and click the "Save Changes" button.
  4. Clear your page cache.
  5. Close every private window, open your WordPress website in a new one, open the page source, and search for termsfeed-autoterms-cookie-consent-callbacks. Confirm that the script holds your object.

Test the Callbacks with the GDPR preference and the Google Consent Mode v2 defaults in the <head>. Close every private window and start each test except "Next page load" in a new one, with the Chrome DevTools Console tab open. Before and after each answer, run dataLayer.filter(e => e[0] === 'consent' && e[1] === 'update') and confirm that the list grew by 1. Its last entry is the newest update.

  • Partial acceptance. Click the "Change my preferences" button, turn on only the switch of the "Tracking cookies" tab, and click the "Save my preferences" button. The entry shows analytics_storage as granted and the 3 advertising signals as denied.
  • Refusal. Click the "I decline" button. The entry shows every signal as denied.
  • Withdrawal after acceptance. Click the "I agree" button, then the "Update cookies preferences" link, select the "Targeting and advertising cookies" tab, set its switch to Inactive, and click the "Save my preferences" button. Without a reload, the entry shows the 3 advertising signals as denied.
  • Next page load. Reload the page from the withdrawal test. A new update entry repeats the saved state.

To keep a consent record, add code that sends each answer to your server inside the same user_consent_saved callback. Copy that code from How to record each answer from user_consent_saved.

The "Callbacks" confirmation and error messages

Callbacks that do not compile open a confirmation on the Customization tab, and Callbacks that are not an object between { and } show an error on either tab. Both leave the consent banner and the vendor scripts working, and your WordPress website does not use the Callbacks until you correct them. Read each message and its fix in Cookie Banner Save Errors in WordPress.

How the "Callbacks" field stays in sync with the "Configuration Parameters"

The "Callbacks" field and the callbacks key of the Configuration Parameters hold the same code, and a save on either tab updates the other. The JSON holds the code as a single escaped string, so edit it in the "Callbacks" field. Only a user with unfiltered_html saves it. Fix a Callbacks save that kept the old code with Code or HTML Not Saving in WordPress.