Dynamic WordPress URL

If you have more than one domains (addon domains) for the same wordpress site you can add the following to your wp-config.php to override the default WP_HOME and WP_SITEURL definitions with dynamic host address. Adding these two definitions also reduces the number of database queries and thus improves site performance. Here is an example (note that you should not include a trailing slash at the end of either URL):

This is for static use (just one domain):

define('WP_HOME', 'http://onyou.ch');
define('WP_SITEURL', 'http://onyou.ch');

For more than one domain set these values dynamically:

define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST']);

Share this

The Author

admin - Hello, my name is Simon, I’am 25 and I’m a software and web developer. My interests span all aspects of programming and development, including ASP, JavaScript, AJAX, PHP, .NET, Java, C#, C++, Objectv-C, Flash, Cocoa, SQL, XML and everything in between. www.simra.ch

One Comment

  1. Haizbeltz
    Jan 24, 2012

    Hi! Thanks a lot for your solution, it has worked for me!. The only problem I have now is that pictures included in my posts seem to be still getting base url or wp_home instead of the dynamic url. It would be great if you went through this as well and had a workaround. Anyway, thanks again for this post. ;-)
    Best regards.

Leave a Reply

*
 
© 2010 onYou GmbH. All Rights Reserved