Two (or more) parallel (sub-)TLDs that are retained when surfing the site / dynamically set the site address?

You could filter the option requests for the host.

In your wp-config.php below the line …

require_once ABSPATH . 'wp-settings.php';

… add the following lines:

add_filter( 'pre_option_home', 'set_current_host' );
add_filter( 'pre_option_siteurl', 'set_current_host' );

function set_current_host()
{
    return 'http://' . $_SERVER['HTTP_HOST'];
}

add_filter() is not available earlier, and you should keep such code in your wp-config.php. I don’t know if there are side effect or cases where it doesn’t work. Should not happen, but test it thoroughly.

Leave a Comment