WPML 语言切换器。 Link 无翻译时转到自定义页面

WPML language switcher. Link to custom page when no translation

我有一个问题。我正在使用 WPML 插件。在 WPML->languages->Language switcher 选项中,我检查了 "Link to home of language for missing translations"。现在,当我单击语言切换器国家标志并且缺少翻译时,它将重定向到主页。我的问题是找不到翻译时如何重定向到自定义页面。我想创建包含文本 "Sorry translation is missing. Please contact us for more info..."

的页面

感谢您的宝贵时间

首先确保您选中了 WPML->语言->语言切换器选项 "Link to home of language for missing translations"。然后用主要语言创建您的自定义翻译未找到页面,并使用 WPML 将其翻译成其他语言。然后将此代码添加到您的 functions.php

add_filter('wpml_ls_language_url', 'redirect_link',10,2);
    function redirect_link($url,$lang){
        if($lang['missing'] == 1) {
            $permalink_to_translation_not_found_page_in_main_language = get_the_permalink(40);  //40 is page id of a custom translation not found page in main language
            $lang['url'] = apply_filters( 'wpml_permalink', $permalink_to_translation_not_found_page_in_main_language , $lang['language_code'] );
        }
        return $lang['url'];
    }

我希望这对某人有用