Site Overlay

Quick address switch in WordPress

WordPress is, by all means, a wonderful piece of software. Like all beautiful things, when you are looking at things very closely, you tend to find the little odd and end that seems to be off track.

One of the most “annoying” aspects of WordPress is when you, for example, have to run a copy of a site in a different URL. I like to run my sites on a myurl.dev site when I am working on them. This makes development easy and responsive and allows me to screw up here and there without the worry of having to put the site offline or in maintenance mode.

Usually you need to update the wp_config table, changing the URLs in the database of your local development machine, which is a hassle. Another quick fix, is to, instead of pointing your local site to myurl.dev, is to actually change your hosts files, so that they point myurl.com to your local machine. Obviously that becomes a headache if you need to check out the original site every now and then.

Finally, one way I have found is by adding this simple little snippet to your functions.php file:

<?php
// where you want your site to point to
$_base_url = "http://myurl.dev/";

// set the constants
define('WP_HOME',$_base_url);
define('WP_SITEURL',WP_HOME);

// actually update the tables.
update_option('siteurl',WP_HOME);
update_option('home',WP_SITEURL);
// once this is run once, ou can comment the lines for increased performance.

Hope this comes in handy.

Comments

comments

2 thoughts on “Quick address switch in WordPress

Leave a Reply

Your email address will not be published.