检测浏览器语言并重定向到另一个URL

时间:2016-06-20 09:12:04

标签: wordpress redirect browser detect

我在“hostingX.com”上安装了WordPress 当浏览器是英文时,我需要重定向到另一个页面。 例如,我的WordPress是西班牙语,您可以通过此URL“hostingX.com/”访问。 我创建了一个名为/ hello-english /的页面。 您可以访问“hostingX.com/hello-english/” 我希望仅当浏览器语言为英语时才将用户重定向到此页面。 我可以这样做吗?

2 个答案:

答案 0 :(得分:1)

add_action( 'init', 'custom_lang_found' );
function custom_lang_found(){
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    if( $lang == "en" ){
        if( is_home() ){
             $url = get_home_url()."/hello-english/";
             wp_redirect( $url );
         }
    }
}

请您尝试上面的代码吗?

答案 1 :(得分:0)

您可以使用xill-language插件。此插件检查浏览器语言并更改为其他语言。我可以在wordpress中使用插件。 https://wordpress.org/plugins/xili-language/