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

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

    To set dynamically the domain and as well as the protocol (http or https), use:

    // Identify the relevant protocol for the current request
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
    
    // Set SITEURL and HOME using a dynamic protocol.
    define('WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST']);
    define('WP_HOME', $protocol . '://' . $_SERVER['HTTP_HOST']);
    

提交回复
热议问题