Websites / Cloudflare
Static Clone Cleanup - WP Runtime Console Errors
SOP: Static Clone Cleanup - WP Runtime Console Errors
Section titled “SOP: Static Clone Cleanup - WP Runtime Console Errors”Last Updated: 2026-06-01
Version: 1.0
Tier: Static clone repair / pre-launch QA
Remove stale WordPress plugin runtime from cloned Astro sites.
When a site is cloned from WordPress or Elementor, the captured HTML often contains script tags and inline JavaScript blocks that only worked inside the original WordPress runtime. On a static clone, those scripts can:
- 404 because
/wp-includes/or/wp-content/JavaScript files do not exist on the static host. - Throw
ReferenceErrorexceptions because inline code calls globals from scripts that were never loaded. - Load old plugin or theme code that does nothing useful on the static build.
- Create console noise that hides real launch blockers.
The target state is a clean browser console: no failed stale script loads and no JavaScript exceptions from dead WordPress or Elementor runtime.
Non-negotiable safety gates
Section titled “Non-negotiable safety gates”This cleanup is allowed to remove dead WordPress runtime scripts. It is not allowed to create visual regressions, missing assets, broken forms, or broken third-party widgets.
Implementation approach
Section titled “Implementation approach”Make the fix in src/layouts/Layout.astro, not by hand-editing individual src/data/*.html files.
The layout receives headHtml and bodyHtml as strings and renders them through:
<Fragment set:html={...} />Apply a sanitizer function to both strings at build time so every captured page is cleaned consistently in one place.
Recommended pattern:
---interface Props { headHtml?: string; bodyHtml?: string;}
const { headHtml = '', bodyHtml = '' } = Astro.props;
function sanitizeClonedHtml(html: string) { let cleaned = html;
// Remove stale WP plugin/theme script files captured from the source site. cleaned = cleaned.replace( /<script\b[^>]*\bsrc=["'][^"']*\/(?:wp-includes|wp-content)\/[^"']*\.js(?:\?[^"']*)?["'][^>]*><\/script>/gi, '' );
// Remove the WordPress emoji settings/loader pair together. cleaned = cleaned .replace(/<script\b[^>]*>\s*window\._wpemojiSettings[\s\S]*?<\/script>/gi, '') .replace(/<script\b[^>]*\bsrc=["'][^"']*\/wp-includes\/js\/wp-emoji-release\.min\.js(?:\?[^"']*)?["'][^>]*><\/script>/gi, '');
// Remove targeted inline calls to globals known to come only from stripped WP runtime. // Keep this list specific. Do not remove broad body content. const deadRuntimeGlobals = [ 'elementorFrontendConfig', 'ElementorProFrontendConfig', 'wpcf7', 'wpforms_settings', 'jQuery.magnificPopup', ];
for (const globalName of deadRuntimeGlobals) { const escaped = globalName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const blockPattern = new RegExp(`<script\\b(?![^>]*\\bsrc=)[^>]*>[\\s\\S]*?${escaped}[\\s\\S]*?<\\/script>`, 'gi'); cleaned = cleaned.replace(blockPattern, ''); }
return cleaned;}
const cleanHeadHtml = sanitizeClonedHtml(headHtml);const cleanBodyHtml = sanitizeClonedHtml(bodyHtml);---
<head> <Fragment set:html={cleanHeadHtml} /></head><body> <Fragment set:html={cleanBodyHtml} /></body>Treat the code above as the pattern, not a universal copy-paste. Adjust exact globals and regexes based on the clone’s console output and captured HTML.
Strip these
Section titled “Strip these”1. Static-host-missing WordPress script files
Section titled “1. Static-host-missing WordPress script files”Remove external <script src="..."> tags pointing at the site’s own WordPress runtime paths:
/wp-includes/...*.js/wp-content/...*.js- WordPress plugin JavaScript files
- WordPress theme JavaScript files
- Elementor runtime JavaScript files that are not present on the static host
These files either 404 on Cloudflare Pages or are dead runtime baggage from the original WordPress environment.
2. Inline blocks that call missing WordPress globals
Section titled “2. Inline blocks that call missing WordPress globals”Remove inline <script> blocks that immediately call a global which was only defined by one of the now-missing WordPress scripts.
Common examples:
- Elementor frontend globals
- WordPress plugin initialization objects
- Contact Form 7 runtime globals when the form was replaced or embedded another way
- WPForms runtime globals when the original plugin form no longer exists
- Gallery, popup, carousel, or animation initializers that only work with missing plugin files
Keep the removal targeted. Do not strip every inline script just because it mentions WordPress once.
3. WordPress emoji settings and loader pair
Section titled “3. WordPress emoji settings and loader pair”Remove both pieces together:
- The inline
window._wpemojiSettingsblock. - The
wp-emoji-release.min.jsloader script.
These two blocks depend on each other. Removing only one can leave avoidable console errors or dead DOM lookups.
Do not strip these
Section titled “Do not strip these”- Scripts loading from live external domains that still work and are needed:
- GoHighLevel / LeadConnector
- Google Tag Manager
- GA4
- tracking pixels
- review widgets
- booking widgets
- CDNs
- Favicon and app icon
<link>tags under/wp-content/uploads/. Those files are usually copied locally during the clone. - Images under
/wp-content/uploads/unless they have been locally mirrored and the references have been rewritten safely. - Scripts that are part of the Astro layout’s own static repair code.
- Any form embed or chat widget code unless it is proven stale and replaced.
Image preservation rule
Section titled “Image preservation rule”Before changing sanitizer patterns, run an asset check for affected pages:
- Search captured head/body files for image references:
grep -RhoE 'https?://[^"'"'() ]+|/wp-content/uploads/[^"'"'() ]+' src/data public src/pages 2>/dev/null | sort -u-
Identify any image URL that could be removed, hidden, path-rewritten, or blocked by the cleanup.
-
Download the image into the static project, usually under
public/images/or the repo’s established image folder. -
Rewrite the reference to the local served path.
-
Build and verify the image exists in
dist/and returns 200 in the preview or local server.
No cleanup is complete if a hero image, gallery item, logo, favicon, background image, form image, or trust badge disappears.
QA checklist
Section titled “QA checklist”After running:
npm run buildConfirm all of the following:
- Build passes with no errors.
-
dist/has zero WordPress runtime script tags:
grep -RInE '<script[^>]+src=["'"'][^"'"']*/wp-(includes|content)/[^"'"']+\.js' dist || true-
dist/has zero remaining inline globals that would throw on load. Search for the exact globals from the console errors, for example:
grep -RInE 'elementorFrontendConfig|ElementorProFrontendConfig|wpcf7|wpforms_settings|_wpemojiSettings' dist || true- Homepage browser console has no failed stale script loads and no reference errors.
- Contact page browser console has no failed stale script loads and no reference errors.
- Gallery page browser console has no failed stale script loads and no reference errors.
- At least one service page browser console has no failed stale script loads and no reference errors.
- Hero, gallery, nav dropdowns, carousels, and forms behave correctly.
- GHL / GoHighLevel chat widget still loads.
- GHL / GoHighLevel or LeadConnector form embeds still load.
- All images that could have been affected still display correctly and are served locally when needed.
- Mobile visual QA passes with no missing media or broken layout.
Browser QA route set
Section titled “Browser QA route set”Minimum route set for this cleanup:
- Homepage
- Contact page
- Gallery or portfolio page, if present
- One parent service page
- One child service page, if present
For each route:
- Open the page in a fresh browser session or clear prior console logs.
- Watch the console during initial load and after interaction.
- Click or tap navigation dropdowns.
- Interact with galleries, carousels, accordions, tabs, and forms.
- Confirm no stale WordPress file requests, 404 script loads, or
ReferenceErrorexceptions appear. - Confirm visible content count did not collapse: H1 present, core sections present, service cards present, gallery images present, CTA/form present.
Failure patterns
Section titled “Failure patterns”Over-broad regex removed real page content
Section titled “Over-broad regex removed real page content”Symptom: H1, gallery, form, or large body sections vanish after the sanitizer runs.
Fix:
- Revert the over-broad pattern.
- Target exact
<script>blocks only. - Prefer matching script
src, script IDs, or specific global initializer blocks. - Rebuild and verify content counts before browser QA.
External widget was removed by mistake
Section titled “External widget was removed by mistake”Symptom: GHL / GoHighLevel chat, form embed, GTM, tracking, review widget, or booking widget disappears.
Fix:
- Add an allowlist for live external domains.
- Restore the external script.
- Verify the embed still loads on the preview and, after approval, production.
Images went missing
Section titled “Images went missing”Symptom: Hero, gallery, favicon, logo, background image, or badge disappears after cleanup.
Fix:
- Download the image locally.
- Serve it from the static project.
- Rewrite the reference safely.
- Verify the file exists in
dist/and returns 200.
Console still shows WordPress errors
Section titled “Console still shows WordPress errors”Symptom: ReferenceError remains after external WP scripts are stripped.
Fix:
- Copy the exact global name from the console.
- Search
src/data,src/layouts, anddistfor the global. - Add a targeted sanitizer rule for that exact inline block.
- Rebuild and repeat route-level console QA.
Approval boundary
Section titled “Approval boundary”This SOP can be used to prepare and verify a cleanup branch or local preview.
It does not authorize any of the following without Jakob approval:
git commitgit mergegit push- pull request merge
- Cloudflare Pages deploy or promotion
- production publish
- DNS, canonical, redirects, indexing, or Search Console changes
- client-facing handoff or external notification