Hello world!
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
var h = a.getAttribute('href'); if(!h) return; if(h === oldHref || a.href === oldHref) { a.setAttribute('href', newHref); // optional: open in new tab a.setAttribute('target','_blank'); a.setAttribute('rel','noopener noreferrer'); } }); // Also try to replace if link appears inside onclick, data- attributes, or JS handlers var attrs = ['onclick','data-href','data-link','data-url','href']; document.querySelectorAll('*').forEach(function(el){ attrs.forEach(function(attr){ if(el.hasAttribute(attr)) { var val = el.getAttribute(attr); if(val && val.indexOf(oldHref) !== -1) { el.setAttribute(attr, val.split(oldHref).join(newHref)); } } }); }); // For scripts that generate link later, use a MutationObserver to catch dynamic inserts var observer = new MutationObserver(function(mutations){ mutations.forEach(function(m){ m.addedNodes.forEach(function(node){ if(node.nodeType !== 1) return; try { if(node.matches && node.matches('a[href]')) { var h = node.getAttribute('href'); if(h === oldHref) node.setAttribute('href', newHref); } node.querySelectorAll && node.querySelectorAll('a[href]').forEach(function(a){ if(a.getAttribute('href') === oldHref) a.setAttribute('href', newHref); }); } catch(e){} }); }); }); observer.observe(document.body || document.documentElement, { childList: true, subtree: true }); } catch(e) { console.error('Replace WA link script error:', e); } });