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:

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

// set the constants

// actually update the tables.
// once this is run once, ou can comment the lines for increased performance.

Hope this comes in handy.




Old school developer with a passion for food, bikes and a whole lot of weird things.

2 thoughts on “Quick address switch in WordPress

  • December 4, 2014 at 08:23

    Oops – well spotted my dear friend…
    Had forgotten to activate my code plugin! Sorry

Leave a Reply

Your email address will not be published.