1. Home
  2. Enhance Panel
  3. WordPress Command Line
  4. How to search and replace in your WordPress database with WP-CLI

How to search and replace in your WordPress database with WP-CLI

WordPress stores your website’s address in many places in its database. If you change domain, or move from http:// to https://, you need to update every one of them. WP-CLI’s search-replace command does this safely, including in data that other methods can break.

New to WP-CLI? Start with getting started with WP-CLI, which shows you how to connect and get to your website’s folder.

Take a backup first. Before making changes, export your database – see how to back up and restore your WordPress database with WP-CLI – or create a manual backup in your Enhance panel.

1. Check your current address

wp option get siteurl
wp option get home

2. Do a dry run first

This shows how many changes would be made, without changing anything:

wp search-replace 'https://old-domain.co.uk' 'https://new-domain.co.uk' --skip-columns=guid --dry-run

Replace the two addresses with your old and new ones. Check the numbers look sensible.

3. Make the changes

Run the same command without --dry-run:

wp search-replace 'https://old-domain.co.uk' 'https://new-domain.co.uk' --skip-columns=guid

4. Clear caches and check your website

wp cache flush

Then check your website in a browser, including images and links.

Example: moving from http to https

wp search-replace 'http://yourdomain.co.uk' 'https://yourdomain.co.uk' --skip-columns=guid --dry-run

Then run it again without --dry-run. Make sure your SSL certificate is working first – see how SSL certificates work on your website.

Tips

  • Be specific. Include https:// in both addresses, so you only change website addresses and not other text that happens to match.
  • Don’t add a / at the end of either address, unless you add it to both.
  • --skip-columns=guid leaves WordPress’s internal post IDs alone, which is recommended.

Need a hand? Please contact our support team. We look after your hosting and WP-CLI; problems inside WordPress plugins and themes are covered in do you support WordPress plugins and themes.

Updated on October 1, 2026
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for? Don't worry we're here to help!
GET SOME HELP!