Don’t let the WordPress address (URL) take the piss out of you!
I love you WordPress. I hate you WordPress! I want to buy the people behind it a pint and hurt them, oh so badly, all at the same time! It’s quite a mixed sense of emotions :)
I’m not going to start my rant about the use of echo inside functions. I might save that for another blog post! Although feel free to follow me on Twitter for a regular stream of WordPress abuse.
What kicked off this post is we needed to deploy our dev copy of wordpress for a client to look at. The problem being, we want a single ’staging’ db which is hosted remotely that we can use both locally and on the staging server we show the customer. Problem is, the URL of the wordpress is fixed in the DB! Doh. I’m probably missing something here, but I couldn’t find a solution to just automatically pick up on the URL!
Anyway, turns out the solution is pretty simple. Open up wp-config.php and insert the following:
define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST']);
This just sets the home url and site url to whatever the current server is. Meaning, you can happily check everything in to SVN and then check it out on to your staging server without having to change any db settings.
I will probably employ a similar trick later to dynamically set the DB config depending on the server.
Love you wordpress!
-
Lee Kelleher
-
Tom
-
Lee Kelleher
-
Mitchell
-
name
