所以动态设置WP\\u SITEURL,WP\\u HOME,我将WP配置覆盖为
define(\'WP_SITEURL\', \'http://\' . $_SERVER[\'SERVER_NAME\'] );
define(\'WP_HOME\', \'http://\' . $_SERVER[\'SERVER_NAME\'] );
但当我调用home\\u url()时,它总是返回x.co.uk主机名
home_url()
不使用任何WordPress常量。它使用调用get_option( \'home\' )
. 要改用WP\\U HOME,请短路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;
}