5

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
  • you can user get_option('home') or other bloginfo('siteurl') to get this site url Commented Sep 17, 2013 at 11:40

1 Answer 1

2

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;
}
1
  • WordPress does this already with the _config_wp_home() and _config_wp_siteurl() functions that are attached to their respective option filters (wp-includes/default-filters.php:175) Commented Mar 26, 2014 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.