Programster's Blog

Tutorials focusing on Linux, programming, and open-source

WordPress - Allow Easy Change Of Domain


Add the following to your wp-config.php before changing your domain.

define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);

Now when you go to your site from a different domain, it doesn't matter.

A Note About Trying To Change Domain Through Database Queries

The theme customizations are stored in a PHP serialized array. This serialization method counts the number of characters in the string values. E.g.


After you replace the values for your old domain to your new one using something like:

UPDATE `wp_options` SET option_value = REPLACE(option_value, '', '');

... then the string count/length will not match, and wordpress will consider the value corrupted, and reset your theme customizations.


Last updated: 2nd July 2021
First published: 5th August 2019