WordPress Cookie Consent Plugin: A/B-Testing & Optimierungsleitfaden (2026)

WordPress Cookie Consent Plugin: A/B Testing & Optimization Guide 2026
headings = content.querySelectorAll('h2, h3'); if (headings.length === 0) { // Hide TOC if no headings var tocDesktop = document.getElementById('toc-desktop'); var tocMobile = document.getElementById('toc-mobile'); if (tocDesktop) tocDesktop.style.display = 'none'; if (tocMobile) tocMobile.style.display = 'none'; return; } var desktopList = document.getElementById('toc-desktop-list'); var mobileList = document.getElementById('toc-mobile-list'); headings.forEach(function (heading, i) { // Ensure heading has an id for linking if (!heading.id) { heading.id = 'heading-' + i; } var depth = heading.tagName === 'H3' ? '3' : '2'; var text = heading.textContent; // Desktop TOC link if (desktopList) { var li = document.createElement('li'); var a = document.createElement('a'); a.href = '#' + heading.id; a.className = 'post-toc__link'; a.setAttribute('data-depth', depth); a.textContent = text; li.appendChild(a); desktopList.appendChild(li); } // Mobile TOC link if (mobileList) { var li2 = document.createElement('li'); var a2 = document.createElement('a'); a2.href = '#' + heading.id; a2.className = 'post-toc-mobile__link'; a2.setAttribute('data-depth', depth); a2.textContent = text; li2.appendChild(a2); mobileList.appendChild(li2); } }); // Mobile TOC toggle var mobileToggle = document.querySelector('.post-toc-mobile__toggle'); var mobilePanel = document.getElementById('toc-mobile'); if (mobileToggle && mobilePanel) { mobileToggle.addEventListener('click', function () { var isOpen = mobilePanel.hasAttribute('data-open'); if (isOpen) { mobilePanel.removeAttribute('data-open'); mobileToggle.setAttribute('aria-expanded', 'false'); } else { mobilePanel.setAttribute('data-open', ''); mobileToggle.setAttribute('aria-expanded', 'true'); } }); } // Desktop TOC: highlight active heading on scroll if ('IntersectionObserver' in window && desktopList) { var tocLinks = desktopList.querySelectorAll('.post-toc__link'); var headingMap = {}; tocLinks.forEach(function (link) { headingMap[link.getAttribute('href').substring(1)] = link; }); // Keep the active TOC link scrolled into view within the (scrollable) sidebar. var tocScroller = document.getElementById('toc-desktop'); function revealInToc(link) { if (!tocScroller || tocScroller.scrollHeight = tocScroller.clientHeight) return; var pad = 16; var top = link.offsetTop; var bottom = top + link.offsetHeight; if (top tocScroller.scrollTop + pad) { tocScroller.scrollTo({ top: top - pad, behavior: 'smooth' }); } else if (bottom > tocScroller.scrollTop + tocScroller.clientHeight - pad) { tocScroller.scrollTo({ top: bottom - tocScroller.clientHeight + pad, behavior: 'smooth' }); } } var tocObserver = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { tocLinks.forEach(function (l) { l.removeAttribute('data-active'); }); var active = headingMap[entry.target.id]; if (active) { active.setAttribute('data-active', ''); revealInToc(active); } } }); }, { rootMargin: '-80px 0px -70% 0px' }); headings.forEach(function (h) { tocObserver.observe(h); }); } })();