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.
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=guidleaves WordPress’s internal post IDs alone, which is recommended.