If you are constantly migrating sites or are planning to change URLs it can be useful to know how to make your WordPress domain agnostic.

What does Domain Agnostic Mean?

Domain agnostic? What the heck does this mean? Don’t worry, it may sound a bit confusing but it’s really not. For instance, say you have a WordPress site that you are developing locally and you want to move it to a server online. Well, we know that the URL that WordPress uses is always saved in the database. If you move the site to the new host and try to login you may find this very difficult. This is because the URLs in the database do not match what’s on the live site.

The Code to Use

Add the following code to your WordPress wp-config.php file. Disclaimer: you should be very careful when editing your config file!

define('WP_HOME',       "http://{$_SERVER['SERVER_NAME']}/");
define('WP_SITEURL',    "http://{$_SERVER['SERVER_NAME']}/");

Now when you visit a WordPress site that has a different URL in the database than the one that is actually pointed to it then it should work and function properly. This bit of code will make it easier for you to move sites and work more effectively. It’s always better to save time and this little bit of code will help you do just that.

Similar Posts