How to change a WordPress network domain

The database

Initially you should update all references to your old domain in the database. The following SQL will take care of that, but first read these notes –

  • This SQL assumes that you are using the default wp_ table prefix. Simply change this to your chosen table prefix if you have changed it.
  • Replace database_name with the name of the database which is used by WordPress.
  • Replace www.old-domain.com with the name of the domain from which you are moving away from.
  • Replace www.new-domain.com with the name of the domain that you are moving to.
  • While it’s unlikely, there may be other references to the old domain (in wp_postmeta for example). To check, in PHPMyAdmin you should select the databse, click Search and search for any references to %www.old-domain.com% in all tables, and then manually update them as required.

Important – The example below will only update references to the old domain for the main site and the first child site. Should you have more sites you will need to replicate the code for the UPDATE wp_*_options... and UPDATE wp_*_posts queries, where * is the ID of the site.

USE `database_name`;
UPDATE `wp_options` AS `o1` SET `o1`.`option_value` = REPLACE(`o1`.`option_value`, 'www.old-domain.com', 'www.new-domain.com') WHERE `o1`.`option_name` IN (
    'siteurl',
    'home'
);
UPDATE `wp_options` AS `o2` SET `o2`.`option_value` = REPLACE(`o2`.`option_value`, 'www.old-domain.com', 'www.new-domain.com') WHERE `o2`.`option_name` IN (
    'siteurl',
    'home'
);
UPDATE `wp_posts` AS `p1` SET `p1`.`guid` = REPLACE(`p1`.`guid`, 'www.old-domain.com', 'www.new-domain.com');
UPDATE `wp_2_posts` AS `p2` SET `p2`.`guid` = REPLACE(`p2`.`guid`, 'www.old-domain.com', 'www.new-domain.com');
UPDATE `wp_blogs` AS `b` SET `b`.`domain` = REPLACE(`b`.`domain`, 'www.old-domain.com', 'www.new-domain.com');
UPDATE `wp_site` AS `s` SET `s`.`domain` = REPLACE(`s`.`domain`, 'www.old-domain.com', 'www.new-domain.com');
UPDATE `wp_sitemeta` AS `sm` SET `sm`.`meta_value` = REPLACE(`sm`.`meta_value`, 'www.old-domain.com', 'www.new-domain.com');
UPDATE `wp_usermeta` AS `um` SET `um`.`meta_value` = REPLACE(`um`.`meta_value`, 'www.old-domain.com', 'www.new-domain.com');

The important bit that I missed

In a network installation a DOMAIN_CURRENT_SITE constant is declared in wp-config.php. Simply open that file and update the value of that constant to your new domain and you should be good to go.


One more consideration

In some cases WP_HOME and WP_SITEURL constants may be declared in wp-config.php, and these will of course override any entries in the database. I’d suggest searching the file for those entries just in case, and if they are present I’d recommed removing them (or at least commenting them out), as it’s much better to use the DB entries.

define('WP_HOME', 'http://www.old-domain.com');
define('WP_SITEURL', 'http://www.old-domain.com');

Leave a Comment