Changing all URLs in your WordPress database

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).

  1. First, log into your server via SSH.
  2. Next, navigate to your WordPress installation. Assuming it's '', you'd probably run the following:
    [server]$ cd ~/
  3. In your site's directory, you can use wp-cli to update the URLs using the following command.
    [server]$ wp search-replace --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.

Did this article answer your questions?

Article last updated PST.