Easy Guide To WP-CLI Search Replace Command
Bulletproof Backups for Your WordPress Website
Fortify your business continuity with foolproof WordPress backups. No data loss, no downtime — just secure, seamless operation.

Your WordPress site needs updated URLs after domain changes or SSL installation. The WP-CLI search replace command safely updates these references throughout your database. Without proper search-replace, visitors hit broken links and your media library shows missing images.
These database operations matter because WordPress stores URLs everywhere. It’s in obvious places like your site options, and in serialized data that powers your widgets, theme customizations, and plugin settings. You can use WP-CLI to make these changes in bulk, in minutes.
This guide covers everything you need to know to successfully change the URLs. You just need a little understanding of how WP-CLI works.
TL;DR: The WP-CLI Search replace command makes changes to your database files. So, take a WP-CLI backup first. Then, use the following command:
wp search-replace ‘old.com’ ‘new.com’ –dry-run
wp search-replace ‘old.com’ ‘new.com’ –skip-columns=guid
Before WP-CLI Search Replace Checklist
Before you run the search replace WP-CLI commands, set yourself up to succeed. A few minutes of prep can save hours of recovery. The goal is simple: have a clean backup, safe access, a working WP-CLI, and a valid target URL. Do these first.
- Backup full site: A WordPress backup is non-negotiable. If something goes wrong, you need a one-click way back. BlogVault backs up files and the database, and it can restore the whole site reliably. You can also take a WP-CLI backup.
- Get SSH access: WP-CLI runs best over SSH. Ask your host for the SSH hostname, username, port, and either a password or SSH key.
- Make sure WP-CLI is installed: Verify with wp –info. If you see version details, you’re good. If not, you will have to install WP-CLI.
- Valid SSL certificate and domain: If you’re moving from http to https or changing domains, make sure the target is ready first. Point DNS to the new server and wait for propagation. Install a valid SSL certificate (e.g., Let’s Encrypt via your host) and confirm https loads without warnings.
Note for Windows Users: This tutorial uses macOS and Linux commands. Windows users can follow the same process but may need slightly different syntax. Use PowerShell or Windows Subsystem for Linux (WSL) for the best experience. SSH commands work the same, but file paths use backslashes (\) instead of forward slashes (/). Consider using PuTTY or Windows Terminal for SSH connections if PowerShell gives you trouble.
Using the WP-CLI Search Replace Command
After you update your site’s URLs using WP-CLI, your database still contains old URLs in posts, widgets, theme settings, and plugin configurations. The WP-CLI search-replace command finds these leftover references and updates them automatically. This step is critical because WordPress stores URLs in serialized data that can’t be safely changed with manual SQL queries – WP-CLI handles the serialization properly so your widgets and theme customizations don’t break.
- Connect to your server: Open Terminal and SSH into your server:
ssh username@yourserver.com -p 22
- Navigate to your WordPress directory:
cd /path/to/your/wordpress/site
The path varies depending on where your WordPress installation is.
- Back up your database first: Run the following command to take a WP-CLI database backup:
wp db export backup-$(date +%Y%m%d).sql
- Preview changes with dry run:
Test what will be replaced without making actual changes:
wp search-replace 'http://old.com' 'https://new.com' --dry-run --report-changed-only --all-tables-with-prefix --skip-columns=guid
Review the output carefully. This shows exactly what URLs will change and in which database tables.
- Execute the search-replace
Once you’re confident the preview looks correct, run the actual replacement:
wp search-replace 'http://old.com' 'https://new.com' --all-tables-with-prefix --skip-columns=guid --report-changed-only
- Clear caches:
Flush WordPress caches so the changes appear immediately:
wp cache flush
- Check everything:
Review all your pages, links, buttons, widgets, images, etc. Make sure everything is working perfectly fine.
Troubleshooting WP-CLI Search Replace
The search replace WP-CLi command helps with problems like mixed-content issues. However, it is a very common to have issues with media. This often happens after a wordpress database search and replace. In this section we’ll talk about why this is happening and how to fix it.
Broken Media After Search and Replace
What you’ll see: Your media library shows placeholder images instead of actual photos. Existing posts display broken image links. Gallery blocks show empty spaces where images should be.
Why is this happening?
You modified GUID columns during your search-replace operation. WordPress uses these permanent identifiers to link media files to posts and pages. When you change site url wordpress cli and accidentally update GUIDs, you break those connections permanently.
Fixing the problem:
Restore your backup. Then rerun the command with –skip-columns=guid.
wp search-replace 'old.com' 'new.com' --skip-columns=guid --all-tables-with-prefix --report-changed-only
Easy alternative to WP-CLI Search Replace
If you can’t access WP-CLI, there are other solutions. We usually recommend that you use the Better Search Replace plugin by WP Engine.
Better Search Replace is the go-to plugin for WordPress users trying to migrate their site. It creates an admin interface that lets you run search-replace operations through your browser. It was very easy to use and you’re done in a few clicks. It’s the far easier and less technical alternative to WP-CLi.
Final Thoughts:
WP-CLI search-replace command is an easy, no-nonsense way to help with changing your URL. You don’t need a plugin, just a few simple commands. However, the catch is that if you’re not familiar or careful, these commands could be more trouble.
So, keep a few things in mind as you navigate this princess. First, always take a backup. If you use a backup plugin, this will be automated and you can relax. Second, always test with –dry-run before executing.
If this is a lot, use a plugin like Better Search & Replace instead. It’s easy to use and requires very little technical know-how.
Tags:
Share it:
You may also like
-
Mirror Backup: What It Is and How It Works
If you manage a WordPress site, you need a backup that protects more than just your posts and pages. Your files, orders, customer data, and settings matter too. When you…
-
Differential Backup 101: Everything You Need to Be Aware Of
Differential backups can make restoring your WordPress site much easier. You usually need just two files: the full backup that started the cycle and the latest valid differential backup. There…
-
Incremental Backup: How It Works, With Examples and Pros and Cons
If your WordPress site is constantly changing, you need a backup system that can keep up. Incremental backups help by saving only what changed since the previous backup instead of…
How do you update and backup your website?
Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.
Updating Everything Manually?
But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.
Backup Your WordPress Site
Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.