Dynamic WordPress URL (for development)

In many cases, we have to create a copy of the WordPress website. Sometimes it is located on a local machine, sometimes on the separate dev server. There are cases when we are using multiple copies of the same website on one computer (when multiple developers are working on various parts of the site).

In each of these cases, we want to adjust the URL of the website. It affects menu items and site behavior. Because we don’t want to perform these changes each time in the database, we are using the following solution:

In the wp-config.php file we are adding a few lines of code:

if ($_SERVER['SERVER_NAME'] != "www.production-website.com") {
    define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
    define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
}

It is as simple as that. We are checking if we are not in the production environment and we are adjusting the site URL and home addresses. Of course, you can use HTTPS instead of HTTP – it depends on your configuration. The above gives us the ability to use virtually any address for our development WordPress installation.

If you want to change the WP address permanently, use the solution described in this article: https://handyman.dulare.com/change-site-url-wordpress/

Leave a Reply

Your email address will not be published. Required fields are marked *