【问题标题】:How do I change my WordPress language in an if condition?如何在 if 条件下更改我的 WordPress 语言?
【发布时间】:2021-08-09 04:31:42
【问题描述】:

我保存了这样的语言 cookie:

function aws_set_language_cookie() {

    //To save the language in a cookie
    
    $current_language = get_locale();
    
    if ($current_language == "es_ES") {
        $result = setcookie('lang', $current_language, time() + (30 * DAY_IN_SECONDS), '/');


    } else {
        $result = setcookie('lang', $current_language, time() + (30 * DAY_IN_SECONDS), '/');
    }

    //To read the cookie and change the language based on the cookie
    
    if (isset($_COOKIE['lang']) && $_COOKIE['lang'] == "es_ES") {
        //need code to change website language to spanish here
    }
}

如何在最后一个 if 语句中将语言更改为西班牙语?

【问题讨论】:

    标签: javascript php wordpress cookies plugins


    【解决方案1】:
     /* you have not mention that your code written with which hook but there is one hook available to change language run time in wordpress */ 
    /* please try you code with below hook function */ 
        
       
    

    add_filter('locale', 'set_my_locale');

        function set_my_locale( $lang ) { 
            if ( isset($_COOKIE['lang']) && $_COOKIE['lang'] == "es_ES") {   
                return 'es_ES'; 
            } else { 
               // return original language 
           }
         }
    

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 1970-01-01
      • 2012-02-04
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多