WordPress主页标语用其他语言

时间:2015-12-22 17:21:31

标签: wordpress multilingual

我的WordPress网站有一个主页标语。我有一个名为 Qtranslate x 的多语言插件。现在我可以为每个页面提供英文版本,但主页的标题仍为荷兰语(原始语言)。这是因为它是在一般主题选项部分中确定的。

有什么我可以做的,以便主页标语也可以是多语言的吗?

1 个答案:

答案 0 :(得分:0)

完整的解决方案允许您通过选项定义标题,但这将使您从正确的方向开始。

在主题的函数文件中,添加此代码(使用wp_title过滤器):

add_filter( 'wp_title', 'my_title_filter', 1, 2 );

function my_title_filter($title, $sep) {

    // Only do this on the home page!
    if (! is_home() && ! is_front_page()) {
        return $title;
    }        
    // Get the language.  You've not included details, so this code is for the WPML Multilingual CMS plugin
    $language = ICL_LANGUAGE_CODE;

    // If the above doesn't work, try this:
    // $language = get_bloginfo("language");

    // Change the title based on the language
    switch ($language) {
        case 'en-US':
            return 'My English Title';
        case 'es-ES':
            return 'Mi español Título';
        // Other languages here....
        case 'nl-BE':
        default:
            return $title;
    }
}

语言标识符的一个来源(可能不是最好的)在这里:http://www.i18nguy.com/unicode/language-identifiers.html