Add data-cookieconsent="ignore" to Gravity Forms <script> tag

Hi there,

I need to add a parameter to all Gravity Forms tags in HTML. The scripts are enqueueing automatically via a shortcode. The parameter is data-cookieconsent=“ignore” - this is used by cookiebot to skip these scripts from blocking. From my testing, I’ve found out that somehow Cookiebot is blocking AJAX calls for Gravity Forms (but only in Safari, not sure why).

Thank you

Hi @marianssen
To add a parameter to all Gravity Forms tags in your HTML, you can use JavaScript to modify the tags after they have been enqueued. Here is an example of how you could do this:

Add the following script to your website, making sure to replace “YOUR-FORM-ID” with the actual ID of your form:

<script>
    document.addEventListener('DOMContentLoaded', function() {
        var forms = document.querySelectorAll('#gform_wrapper_YOUR-FORM-ID');
        for (var i = 0; i < forms.length; i++) {
            forms[i].setAttribute('data-cookieconsent', 'ignore');
        }
    });
</script>

This script will wait for the DOM to load, and then it will find all Gravity Forms tags with an ID of “YOUR-FORM-ID” and add the “data-cookieconsent” attribute with a value of “ignore” to each of them.

If you want to add the parameter to all Gravity Forms on your website, you can remove the ID filter from the script and use the following instead:

<script>
    document.addEventListener('DOMContentLoaded', function() {
        var forms = document.querySelectorAll('[id^=gform_wrapper_]');
        for (var i = 0; i < forms.length; i++) {
            forms[i].setAttribute('data-cookieconsent', 'ignore');
        }
    });
</script>

This will find all elements with an ID that starts with “gform_wrapper_” and add the “data-cookieconsent” attribute with a value of “ignore” to each of them.

I hope this helps! Let me know if you have any questions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.