Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
you can user get_option('home') or other bloginfo('siteurl') to get this site url –  Vikas Gautam Sep 17 '13 at 11:40

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;
}
share|improve this answer
    
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) –  TheDeadMedic Mar 26 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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