I created a wordpress site and name hostname as x.co.uk, x.com, x.in…

In wp-option table the site and home url as x.co.uk. I want dynamically for loading other host name also.

So dynamically set WP_SITEURL, WP_HOME, i override the wp-config as

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

but when i call home_url() it always return x.co.uk hostname

Thanks Advance

1 Answer
1

So dynamically set WP_SITEURL, WP_HOME, i override the wp-config as

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

but when i call home_url() it always return x.co.uk hostname

home_url() does not make use of any WordPress constants. It uses a call to get_option( 'home' ). To use WP_HOME instead, short circuit get_option():

add_filter( 'pre_option_home', 'wpse_114486_change_get_option_home' );
/**
 * Change get_option( 'home' ) and any functions that rely on it to use
 * the value of the WP_HOME constant.
 *
 * This is not fully tested. Many WordPress functions depend on the value of
 * get_option( 'home' ). The ramifications of this filter should be tested
 * thoroughly.
 */
function wpse_114486_change_get_option_home( $option ) {

    if ( defined ( 'WP_HOME' ) )
        return WP_HOME;

    return false;
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *