Tag a custom script for consent

2 min read Updated June 2026

Any script that sets cookies or loads a third-party tool can be held until the visitor consents — not just Google’s. You do it by tagging the script with the service it belongs to.

The two attributes that matter

Take the <script> you want to gate and make two changes:

  • Set type="text/plain" so the browser doesn’t run it on load.
  • Add data-cc-name="<service-slug>" so ClearConsent knows which consent unlocks it.

The slug must match a service you added under Services.

Tag an inline script

HTML
<script type="text/plain" data-cc-name="chat-widget">
  // runs only after the visitor consents to "chat-widget"
  loadChatWidget();
</script>

Tag a script that loads from a URL

For an external file, keep the src and add the same two attributes:

HTML
<script type="text/plain" data-cc-name="meta-pixel"
        src="https://connect.facebook.net/en_US/fbevents.js"></script>

When the script runs

ClearConsent activates the tagged script the moment the visitor consents to its service — either from the banner or the preferences modal. If they refuse, it never runs.

Can’t edit the script tag?
If a tracker is added by a theme or another plugin and you can’t reach its <script> tag, ClearConsent Pro’s Script Manager can hold it for you without editing code. See Manage scripts with Script Manager.
Was this article helpful?
Thanks for your feedback!

Related articles