WordPress hardcodes the site's domain name into the database in such things as image and link urls. This is a problem if you migrate the site to another domain, because when you click on a link on your new site, it redirects back to the old site.
To update the URLs in your database, you can use a plugin or command line
Using a plugin
Below are a couple of plugins that work to change all URLs in your database.
Using the command line
If you are familiar with the command line, you can run the following command for the same effect (assuming you saved the old WordPress address).
- First, log into your server via SSH.
- Next, navigate to your WordPress installation. Assuming it's 'example.com', you'd probably run the following:
[server]$ cd ~/example.com
- In your site's directory, you can use wp-cli to update the URLs using the following command.
[server]$ wp search-replace http://example.com http://new.example.com --dry-run
The --dry-run call at the end tests the address
If the changes make sense to you, then run the above command again without the 'dry-run' call.
At this point, all URLs within your WordPress site will use the new domain name.