October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

WordPress Changed My JavaScript Regex: Find Where the Live Page Breaks

A JavaScript regex that breaks only on a published WordPress page may have changed during saving or rendering. Compare the editor, saved content, page source, DOM, and runtime to locate the first difference.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a JavaScript regex works in the editor but fails on the published page, compare the code at each stage before blaming WordPress or the regex. Check the editor, saved post content, published page source, parsed browser DOM, and runtime value. The first stage where the text changes points to the likely cause.

Why “only the live page broke” matters

Editing, saving, rendering, and browser parsing are separate steps. A script can look correct in the editor while the saved content is sanitized, or the saved content can remain intact while a shortcode, template, theme, or plugin changes what the page emits. The browser DOM and the value JavaScript ultimately uses are further steps, not proof of what WordPress saved.

As an Amazon Associate I earn from qualifying purchases.

A literal ampersand (&) inside a JavaScript regex literal is not, by itself, evidence of invalid regular-expression syntax. First inspect the exact pattern and flags. Also note whether the code uses a regex literal such as /pattern/ or constructs a pattern from a string with new RegExp(...); those are different representations to compare.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Trace the first point where the text changes

  1. Copy the exact pattern from the editor. Include its delimiters and flags, and record whether it is a literal or a string passed to RegExp.
  2. Inspect the saved post or block content. If the pattern or its surrounding <script> tag is already altered or missing, look at the editing surface, WordPress version, account capability, and save-time sanitization.
  3. Open the published page’s source. Use the browser’s View Source feature and search for the exact pattern. This shows the HTML response before the browser builds its DOM. Compare it with the saved content.
  4. Inspect the parsed DOM and runtime value separately. If View Source has the expected text but the DOM or runtime pattern does not, investigate browser parsing, script construction, and application code. That difference does not by itself identify which one is responsible.
  5. Follow the output path. If a shortcode, page builder, PHP template, or other rendering layer supplies the code, inspect its returned or emitted string and filters that run afterward.

Keep the original pattern and each stage’s output side by side. The diagnosis is the earliest stage at which they differ—not necessarily the stage where the browser finally reports an error.

When saving or editing changes the code

Custom HTML blocks and permissions

WordPress documentation says that, beginning with WordPress 7.0, the Custom HTML block has separate HTML, CSS, and JavaScript editing panels. The CSS and JavaScript panels are available only to users with the unfiltered_html capability. For users without that capability, WordPress can sanitize block content with wp_kses() on save or update, stripping disallowed markup such as <script>. Check the installed version, user capability, and block type rather than assuming the code was stored unchanged. See WordPress’s Custom HTML documentation.

Classic Editor and other editing surfaces

The Classic Editor’s visual and HTML modes handle code differently, and behavior can vary with WordPress version, editor, and plugins. Its documentation notes entity spellings such as &amp; and &#038;. If the code changes between editor modes or after saving, compare the stored content directly and identify which editor or builder handled it. See the WordPress Editor documentation.

When saved content is right but the live output is not

Shortcode output

WordPress processes registered shortcodes when the_content is displayed. The shortcode handler’s returned string replaces the shortcode in the post content. If the script comes from a shortcode, inspect the callback’s return value and any later content filters. A callback that includes content is responsible for encoding or escaping it appropriately for the output context. See the Shortcode API handbook.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PHP output and escaping context

Determine whether a value is being inserted as HTML text, an HTML attribute, JavaScript data, or script source. Escaping is context-specific: esc_attr() encodes ampersands and other special characters for HTML attributes such as alt, value, and title. It is not a general-purpose way to escape JavaScript source, and applying it to an entire script can produce the wrong output. See the WordPress esc_attr() reference.

Theme, plugin, and template filters

If the saved content is intact but View Source differs, inspect shortcode callbacks, template output, and theme or plugin filters that run while the page is rendered. The symptom alone does not establish that a particular plugin or theme caused it. Reproduce the issue on a staging copy and isolate the relevant filters or components there.

What WordPress’s HTML handling does—and does not—show

The WordPress HTML Tag Processor documentation treats SCRIPT contents as raw plaintext; it distinguishes them from elements such as TITLE and TEXTAREA, where character references are decoded. That is a reason to inspect the exact delivered source rather than assume an entity-looking sequence will be decoded inside script text. The documentation also describes specific safety escaping around script content, with exceptions including RegExp.prototype.source. It does not establish that WordPress generally rewrites ampersands in JavaScript regexes. See the WP_HTML_Tag_Processor reference.

wpautop() formats paragraph breaks and may turn remaining line breaks into <br />. Its reference says line breaks inside <script>, <style>, and <svg> are not affected, so it is a weaker explanation when the specific symptom is a changed literal ampersand. See the wpautop() reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use the output differences to choose the next check

First difference appears in Investigate next
Editor versus saved content Editor or block type, WordPress version, user capability, and save-time sanitization.
Saved content versus View Source Shortcode callback, template or PHP output, and theme or plugin filters.
View Source versus parsed DOM Browser parsing and the markup surrounding the script.
DOM text versus runtime pattern Script construction and application code that creates or transforms the regex.

If the pattern works when served from a separate JavaScript file or on a minimal staging page, that comparison can help narrow the issue to the page’s content or rendering path. It does not, by itself, identify a specific filter or plugin.

What you need for a site-specific diagnosis

The symptom alone does not reveal the cause. A precise diagnosis requires the WordPress version, editing surface or builder, the user’s capability, the exact regex and flags, and the code path that emits it—such as shortcode or template code—along with the relevant theme and plugin context. Comparing the exact text at the stages above will show where to investigate without treating an ampersand or an entity spelling as proof of a regex error.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.