Search-and-Replace on Base64 Page-Builder Content: Why It Silently Fails

Date:

You wrote a snippet to change one label in a page-builder template, activated it, saw no error – and the old text is still there. The snippet didn’t fail. It ran, matched nothing, and reported success. The value you were editing is wrapped twice, and your search string only accounted for one layer.

The short answer: Page builders often store a block’s content as a single base64 string, and the text inside that string is JSON-escaped – so a quote is stored as \", not ". A search-and-replace for text="OldName" finds zero matches against the real bytes text=\"OldName\", changes nothing, and still finishes without an error. The fix is two habits: decode the value and match the form actually on disk (the escaped one), and verify by reading it back and counting occurrences – because “no error” is not the same as “changed.”
Editing encoded page-builder content without a silent no-opDecode and match the stored form, then read it back to prove the change
1. Decode, don't guess

base64-decode the value first. The text is JSON-escaped inside, so quotes are stored as \" not ".

2. Match the stored form

Replace text=\"OldName\", never the bare text="OldName". Re-encode, then save.

3. Read it back, count

Re-read the stored value. The old string must count 0. "No error" is not "changed".

Guard the run with a versioned flag – a stale 'skip' from an earlier attempt silently blocks the fix.

Why the value is wrapped twice

Many page builders don’t store a block as HTML. They store it as a serialized string of shortcodes and settings, then base64-encode the whole thing so quotes, angle brackets, and CSS survive being pasted into a database field – the same reason themes base64-encode text in the first place. But before that encoding, the builder usually JSON-escapes the string, because the block’s attributes are themselves quoted. The result is two layers: base64 on the outside, escaped text on the inside. Decode the base64 and you don’t get text="OldName" – you get text=\"OldName\", with a backslash in front of every quote.

The value on your screen and the bytes in the database are not the same string. A search-and-replace matches the bytes, and the bytes are escaped.

The silent no-op

Here is the trap in two lines. The first is what almost everyone writes; the second is what actually matches the stored bytes:

// No-op: the builder stored JSON-escaped quotes, so this never matches
str_replace('text="OldName"',  'text="NewName"',  $decoded);

// Matches the form actually on disk: text=\"OldName\"
str_replace('text=\"OldName\"', 'text=\"NewName\"', $decoded);
Code language: PHP (php)

The first line isn’t an error – it’s a replace that finds nothing to replace. Your snippet decodes the value, runs the no-op, re-encodes the unchanged string, and saves it right back. Every log line is green. The label on the site never moves. The bug is invisible precisely because nothing went wrong; it just didn’t go right either.

Match the form on disk

The habit that prevents this is simple: decode first, then look at the real bytes before you write the pattern. Dump the decoded value and search it for the literal you expect. If you see text=\"OldName\", your search string needs the backslashes. If a value looks doubly odd – a base64 string inside the decoded content – that attribute is encoded again, and you match it at its own layer, not the outer one. Never write the pattern from what the editor renders; write it from what the store contains.

This is builder-agnostic. The specific escaping differs, but tagDiv, WPBakery, Elementor, and Divi all serialize and encode before storing, so the string you must match is rarely the string you see. The value also lives in a place standard REST can’t reach, which is why you’re editing it with a snippet at all. The same encoding blind spot bites at scale during a domain migration, where a site-wide search-replace sails past every encoded block. On tagDiv, each responsive setting is base64 JSON with one value per device; the walkthrough on customizing the tagDiv Newspaper theme edits one of them step by step.

Verify by reading it back

The second habit is what turns a silent failure into a caught one: after you save, re-read the value and count. Do not trust the absence of an error. Count the occurrences of the old string before and after, and assert the “after” is zero:

// "Activated, no error" is not "changed." Count before and after.
$before = substr_count($decoded, 'text=\"OldName\"');   // expect 1 or more
// ...replace, re-encode, wp_update_post()...
// then re-read the STORED value, decode it again, and assert:
$after  = substr_count($reread, 'text=\"OldName\"');    // must be 0
Code language: PHP (php)

A zero-match replace and a successful replace look identical from the outside – same green log, same “done.” The only thing that tells them apart is a count taken from the value after it was written. Reading it back also catches the neighboring gotcha: a compiled-template or object cache that still serves the old string even though the stored value is now correct. If the count is zero but the page still shows the old text, clear the builder’s cache, not the value.

A snippet that changed nothing and a snippet that worked print the same success line. Only a re-read tells you which one you actually ran.

Guard the run so the fix isn’t blocked

One more trap sits behind the first. A well-built one-time snippet uses a guard flag so it runs once and re-runs safely – see the one-time setter snippet pattern. But if your first, broken attempt set that flag (even to record “nothing to change”), your corrected snippet reads the flag, thinks it already ran, and does nothing. Bump the flag’s version – mytask_done_v1 becomes v2 – whenever you change the snippet’s logic, so a stale marker from a failed run can never block the fix.

The short version

When you script an edit to page-builder content, remember the value is wrapped twice: base64 on the outside, JSON-escaped text inside. A search-and-replace for text="OldName" matches nothing, changes nothing, and still reports success, because the real bytes are text=\"OldName\". Decode the value and match the escaped form actually on disk, then verify by re-reading the stored value and counting that the old string is gone – “no error” is not “changed.” If a corrected snippet still does nothing, check for a stale run-once guard flag and bump its version. If the count is zero but the old text persists, clear the builder’s cache.

Frequently Asked Questions

Will a search-replace plugin or wp search-replace fix encoded blocks?

No. Those tools match the raw bytes in the database, and inside a base64 value your text never appears as plain bytes, so they pass over it without a match. wp search-replace does handle PHP-serialized data, but it does not decode base64. For an encoded block you have to decode the value, replace the escaped form, re-encode it and save it, one value at a time, then read it back and count.

The value is correct in the database but the page still shows the old text. Why?

That’s caching, not the edit. Page builders keep compiled templates or an object cache, and it can keep serving the previous render after the stored value changes. Once your count confirms the value is updated, clear the builder’s template or object cache so the front end re-renders from the new value.

Share post:

Subscribe

Popular

More like this
Related

WooCommerce Search by SKU or ISBN Finds Nothing? It Never Looks There

A shopper types the SKU from your catalog, or the ISBN printed on the back of a book, and gets "No products were found". The product is right there, and the number is on its page. Search simply never reads that part of the product.

Computer Slow but CPU and Memory Look Normal? Check the Handle Count

Chrome takes a minute to open, or doesn't open at all. Every click waits. You open Task Manager expecting to find the culprit, and it tells you everything is fine. Here is the number that isn't, and the fix that takes two minutes.

Kernel-Power 41 Tells You Your PC Restarted, Not Why

Your PC restarts with no blue screen, and the only clue is a critical event saying it didn't shut down cleanly. Here is how to get from that event to a short list of suspects.

Set Up WordPress SMTP Without a Plugin, Even on a Multisite Network

WordPress mail goes out as wordpress@ your domain, from the web server, and lands in spam. An SMTP plugin fixes that. So do about twenty lines of code, and on a network of sites the code can give every site its own mailbox and its own password.