如果翻译不存在,则显示 'This page not translated'。 WP 和 WPML
Show 'This page not translated' if translation doesn't exist. WP and WPML
好吧,我有一个使用 WPML 的 WordPress 网站。并非我所有的页面都被翻译成 EN 版本。我知道要实现以下。当有人试图转到不存在的 URL 时,我想显示 him/her 'Not translated page'(建议以另一种语言观察此内容)。
我怎样才能意识到呢?谢谢!
add_action('wp_head', 'wpml_custom');
function wpml_custom() {
global $wp_query;
$postId = $wp_query->post->ID;
$postType = $wp_query->post->post_type;
$args = [
'element_id' => $postId, 'element_type' => $postType
];
$translation = apply_filters( 'wpml_element_language_details', null, $args );
$currentLang = apply_filters( 'wpml_current_language', null );
if (preg_match('/^\/$/', $_SERVER['REQUEST_URI'])) {
return;
} elseif ($translation->language_code !== $currentLang) {
require get_template_directory() . '/no-translation.php';
exit();
}
}
好吧,我有一个使用 WPML 的 WordPress 网站。并非我所有的页面都被翻译成 EN 版本。我知道要实现以下。当有人试图转到不存在的 URL 时,我想显示 him/her 'Not translated page'(建议以另一种语言观察此内容)。 我怎样才能意识到呢?谢谢!
add_action('wp_head', 'wpml_custom');
function wpml_custom() {
global $wp_query;
$postId = $wp_query->post->ID;
$postType = $wp_query->post->post_type;
$args = [
'element_id' => $postId, 'element_type' => $postType
];
$translation = apply_filters( 'wpml_element_language_details', null, $args );
$currentLang = apply_filters( 'wpml_current_language', null );
if (preg_match('/^\/$/', $_SERVER['REQUEST_URI'])) {
return;
} elseif ($translation->language_code !== $currentLang) {
require get_template_directory() . '/no-translation.php';
exit();
}
}