diff --git a/CLAUDE.md b/CLAUDE.md
index 1a225d5..476542b 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -30,7 +30,9 @@ Single serialized option: `att_consent_settings`. Access via `ATT_Consent::get_s
{prefix}att_cc_scripts (id, name, snippet, category, placement, status, priority, created_at, updated_at)
```
-Scripts are passed to frontend JS via the inline config object, NOT rendered in PHP (they'd execute before consent). Injected into DOM by `consent-manager.js` after consent.
+Scripts are rendered in PHP as inert `' . "\n";
+ }
+ }
+
+ return $output;
+ }
}
diff --git a/public/js/consent-manager.js b/public/js/consent-manager.js
index 4997e97..b99333e 100644
--- a/public/js/consent-manager.js
+++ b/public/js/consent-manager.js
@@ -129,32 +129,68 @@ var AttConsent = (function() {
/**
* Execute custom scripts for the consented categories.
+ * Scans the DOM for inert type="text/plain" script tags and template tags
+ * with matching data-att-cc-category attributes, then activates them.
*
* @param {Object} categories Consent categories.
*/
function executeConsentedScripts(categories) {
- var scripts = config.scripts || {};
+ var cats = Object.keys(categories).filter(function(cat) {
+ return categories[cat];
+ });
+ if (!cats.length) return;
- Object.keys(categories).forEach(function(cat) {
- if (!categories[cat] || !scripts[cat]) {
+ var selectors = [];
+ cats.forEach(function(cat) {
+ selectors.push('script[type="text/plain"][data-att-cc-category="' + cat + '"]');
+ selectors.push('template[data-att-cc-category="' + cat + '"][data-att-cc-type="html"]');
+ });
+
+ var elements = document.querySelectorAll(selectors.join(','));
+ Array.prototype.slice.call(elements).forEach(function(el) {
+ if (el.nodeName === 'SCRIPT') {
+ activateScript(el);
+ } else if (el.nodeName === 'TEMPLATE') {
+ activateTemplate(el);
+ }
+ });
+ }
+
+ /**
+ * Activate an inert script element by creating a fresh