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

前端 未结 3 475
难免孤独
难免孤独 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:23

    I've found another pretty way to achieve the work:

    After I checked for the source code of the kernel, I found that there are distinct filters called option_xxx on each options.

    So, for my task, I tried to use the option_siteurl and option_home filter to hold that options to load, just to prevent the option to load, maintaining the SERVER_NAME it has:

    function replace_siteurl($val) {
        return 'http://'.$_SERVER['HTTP_HOST'];
    }
    add_filter('option_siteurl', 'replace_siteurl');
    add_filter('option_home', 'replace_siteurl');
    

    Using this way, it has no need to change the wp_config.php file, and can be easily add to a theme or a plugin.

提交回复
热议问题