21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Blog · WebJi® India

WordPress Search and Replace URLs

Quick answer

A WordPress search and replace updates every old URL stored in the database after a domain or https change. Use WP-CLI's search-replace or the Better Search Replace plugin, because they rewrite the length counts inside serialized settings that a plain SQL UPDATE breaks. Back up first, dry-run, skip the GUID column, then run the live pass.

For developers and site owners moving WordPress to a new domain, to https or between staging and live.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
3 min
Sections
7
Updated
14 Nov 2026
Written by
WebJi® team

When do you need to search and replace URLs in WordPress?

You need a database-wide URL replace whenever the site's address changes: a domain move, a switch from http to https, or a copy to a staging or local host. WordPress stores full links not only in Settings › General but inside post content, widgets, menus and page-builder data, and those keep pointing at the old address.

Changing the two address fields is enough only on a brand-new site. On any site that has been edited for a while, run a database replace as part of the move, alongside the steps in the domain change walkthrough.

Why does a plain SQL UPDATE break WordPress URLs?

Many plugin and theme settings are stored as PHP serialized strings that record each value's character count; a raw SQL replace changes the text but not the count, so WordPress can no longer read the value and drops it. Widgets, theme options and builder layouts then appear empty even though the row is still in the table.

s:22:"https://old.example.in";   ← valid, 22 characters
s:22:"https://newbrand.example.in";   ← broken: now 27 characters

WP-CLI and Better Search Replace unserialize the value, change the URL, write the new length and serialize it again. Use raw SQL only on a plain text column you have inspected yourself.

How do you replace WordPress URLs with WP-CLI?

Export the database, run wp search-replace with --dry-run to see the counts, then run it again without the flag. Run the commands from the WordPress directory over SSH.

wp db export before-replace.sql
wp search-replace 'https://old.example.in' 'https://new.example.in' --skip-columns=guid --dry-run --report-changed-only
wp search-replace 'https://old.example.in' 'https://new.example.in' --skip-columns=guid --report-changed-only
wp cache flush
  • Default scope: without extra flags WP-CLI touches only the tables registered with WordPress, which is normally what you want.
  • --all-tables: also scans every table in the database, including other apps sharing it; use it only when you know those tables need changing.
  • --skip-columns=guid: leaves post GUIDs alone, as WordPress recommends.
  • Zero counts: a table reporting 0 simply does not contain the old URL.

Move the export file out of public_html when you are done. If the dry run itself errors, email support@webji.services with the command and the error text.

How do you replace URLs with the Better Search Replace plugin?

Install Better Search Replace, open Tools › Better Search Replace, enter the old and new URLs, select tables, tick "Run as dry run" and check the counts before the live pass. It is the usual route when WP-CLI is not available.

  1. Take a database backup from your hosting panel or a backup plugin.
  2. Enter the old URL and the new URL with the same scheme, host and trailing-slash style on both sides.
  3. Select the WordPress tables, leaving log and cache tables out.
  4. Run as dry run and read the per-table counts.
  5. Untick dry run and run again, then deactivate and delete the plugin.

Which WordPress tables should the URL replace include?

Include options, posts and postmeta (plus termmeta, usermeta and comments where links appear); skip log, session and cache tables, and leave post GUIDs alone.

WordPress tables to include in a URL search and replace
TableInclude?What it holds
wp_optionsYessiteurl, home, widget and plugin settings
wp_postsYes (skip the guid column)Post and page content, excerpts, menu items
wp_postmetaYesPage-builder layouts, custom fields
wp_termmeta, wp_usermetaIf usedCategory images, profile links
wp_commentsOnly if comments link to your old URLComment text and author URLs
Log, cache, session tablesNoTemporary data, not the live site

Your prefix may not be wp_; check $table_prefix in wp-config.php.

Why do some old URLs survive the replace?

Page builders and block attributes often store URLs as JSON with escaped slashes, such as https:\/\/old.example.in, which a plain-URL search does not match. Run a second pass for the escaped form, or use the builder's own tool.

wp search-replace 'https:\/\/old.example.in' 'https:\/\/new.example.in' --skip-columns=guid --dry-run

Elementor, for example, has a Replace URL tool under Elementor › Tools that also regenerates its CSS files. Hard-coded URLs inside theme files or custom CSS are not in the database at all and must be edited in the files.

How do you switch WordPress from http to https and check the result?

Install the certificate, replace http://example.in with https://example.in using the steps above, confirm both address fields show https, then add a 301 redirect from http. The redirect is covered in the HTTP to HTTPS guide.

  1. Open Settings › General; both URL fields must show the new address.
  2. In a private window, load the home page, one post, one image and one form.
  3. Check a widget area and a menu; empty areas suggest a damaged serialized row.
  4. If a builder layout is blank, restore the backup and repeat with a length-aware tool rather than patching with more SQL.

A host move is the same replace after files and database are copied; the copy itself is covered in migrating a WordPress site. On WebJi® WordPress hosting, the staging tool on WordPress Unlimited plans gives you a safe place to rehearse it.

FAQ

Frequently asked questions

Should I change the GUID column when moving domains?

No. WordPress treats a post's GUID as a permanent identifier, mainly for feed readers, and its documentation advises against changing it. Visitors never see it, so the visible site works correctly with old GUIDs left in place.

Can I undo a WordPress search and replace?

Only by restoring the backup you took first, for example with wp db import before-replace.sql. Running the replace in reverse can also catch strings that were already present before, so the backup is the reliable undo.

Why does wp-admin redirect to the old domain after a move?

The home and siteurl options still hold the old address, or WP_HOME and WP_SITEURL are hard-coded in wp-config.php. Update those constants, or run wp option update home 'https://new.example.in' and the same for siteurl, then clear caches.

Does search and replace work on WordPress multisite?

Yes, with --network in WP-CLI to cover every site's tables. Multisite also stores domains in wp_blogs and wp_site, so check those rows after a domain change and test each subsite.

Checked 14 November 2026 against the WP-CLI search-replace documentation · Reviewed by the WebJi® team, Jaipur.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.