Skip to content

[00] Subset Sync, Guide

Elementor and widgets broken after a WordPress migration

Why widgets, theme settings and Elementor pages break after a find and replace on the database, and how to change URLs without breaking serialized data.

Published
Fix uses
Subset Sync (free)
Reading time
4 min

What breaks, and when

You move a site to a new domain, or from staging to live, and run a find and replace on the database to change the URL. The site loads, but widgets are missing, the theme’s Customizer settings are back to their defaults, and some Elementor pages still point at the old domain.

Two storage formats cause this. WordPress and most plugins store settings as PHP serialized strings, and a plain find and replace corrupts them. Elementor stores page content as JSON with escaped slashes, and a plain find and replace doesn’t match it.

Why a text replace breaks serialized data

PHP’s serialize() writes every string with its length in bytes in front of it. An option holding a logo URL looks like this in the wp_options table:

a:1:{s:4:"logo";s:36:"https://staging.example.com/logo.png";}

s:36 says the string that follows is 36 bytes long. Replace https://staging.example.com with https://example.com in a SQL dump using a text editor, or with SQL’s REPLACE(), and you get this:

- a:1:{s:4:"logo";s:36:"https://staging.example.com/logo.png";}
+ a:1:{s:4:"logo";s:36:"https://example.com/logo.png";}

The string is now 28 bytes, but the value still says 36. PHP’s unserialize() (opens in a new tab) can’t read it and returns false. The correct result needs the length changed too:

a:1:{s:4:"logo";s:28:"https://example.com/logo.png";}

WordPress reads options through maybe_unserialize() (opens in a new tab), which hides the warning and hands back false. Nothing shows an error. The setting reads as empty instead:

  • Theme settings live in a theme_mods_ option. When it isn’t an array, get_theme_mods() (opens in a new tab) returns an empty one, so the theme falls back to its defaults.
  • Widget settings are serialized options too, so a broken one leaves its sidebar empty.
  • Plugin settings stored the same way go back to their defaults, or the plugin asks to be set up again.

The length counts bytes, not characters. An accented letter or an emoji takes two to four bytes, so counting characters by hand gives the wrong number.

Why Elementor pages keep the old URL

Elementor saves each page’s layout as JSON in the _elementor_data post meta. JSON can escape forward slashes, and Elementor’s data has them escaped, so a URL in it reads https:\/\/staging.example.com\/logo.png. A search for https://staging.example.com doesn’t match that text, so those URLs stay as they were.

You can see this in Elementor’s own replace_urls() source (opens in a new tab). It escapes the slashes in both URLs before it runs REPLACE() on _elementor_data.

Fix it without a plugin

If you edited a SQL dump by hand, go back to the original, unedited dump or a backup from before the replace. Values whose lengths are already wrong have lost the information a tool needs to repair them reliably. Import the original, then run the replace again with one of the tools below.

With command line access, wp search-replace (opens in a new tab) handles PHP serialized data, so the lengths stay correct. Run it with --dry-run first to see how many replacements each table would get without saving anything:

wp search-replace 'https://staging.example.com' 'https://example.com' --dry-run
wp search-replace 'https://staging.example.com' 'https://example.com'

A few options help on harder sites:

  • --precise does every replacement in PHP rather than SQL. It’s slower, and the WP-CLI docs say it handles complex serialized data more reliably.
  • --all-tables includes tables without the WordPress table prefix.
  • --export=<file> writes the changed database to a SQL file and leaves the live database alone.

The escaped form in Elementor’s data needs a second pass with the slashes escaped:

wp search-replace 'https:\/\/staging.example.com' 'https:\/\/example.com' --dry-run

Without the command line, Elementor has its own Replace URL tool (opens in a new tab). Open Elementor’s Tools, go to the Replace URL tab, enter the old and new URL and click Replace URL. Then click Clear Files & Data on the General tab and save. The same thing is available as wp elementor replace-urls (opens in a new tab). It only changes _elementor_data, so it won’t repair widgets or theme settings broken by an earlier replace.

Take a database backup before either one. Both write to the live database.

Change URLs as part of the move with Subset Sync

Subset Sync moves the database between sites and does the find and replace as part of the move. Site URLs, http and https and file paths are rewritten everywhere, including inside serialized and JSON data, so the https:\/\/ form in Elementor’s data is replaced in the same pass.

It never unserializes a value. A small tokeniser changes only the string contents and recomputes each byte length, so objects from plugins that aren’t active on the destination come through intact.

Before anything is replaced, you get two safeguards:

  • A preview. Every push and pull shows the tables, row counts, every find and replace pair and sample rewrites of the home option and a post. On the command line, --dry-run prints the preview and stops.
  • A backup. Before a push, pull or import replaces a database, Subset Sync backs it up. The newest three backups are kept, and you can restore one from the Backups tab.

If the damage came from a hand-edited dump, import the original dump instead. On the Migrate tab, choose Import and pick the file. Subset Sync replaces the dump’s site URL with this site’s, and you can add your own pairs under Advanced options → Add find & replace. It reads dumps from mysqldump and WP Migrate as well as its own.

Install it on both sites and connect them with getting started with Subset Sync. The flags for scripted runs, including --find, --replace and --dry-run, are in the Subset Sync WP-CLI reference.