How to set dynamic `home` and `siteurl` in WordPress?

前端 未结 3 470
难免孤独
难免孤独 2021-02-05 17:50

I config the multi-language setting dynamically using the locale filter. Which fetch the sub-domain name to determine the language.

function load_cu         


        
3条回答
  •  情书的邮戳
    2021-02-05 18:12

    You can override the admin settings in the wp-config.php file. So if you want something dynamic, the following should work:

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

    This needs to added before the line

    require_once(ABSPATH . 'wp-settings.php');
    

    or else you may have problems with some content using the wrong URLs, especially theme files.

提交回复
热议问题