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();
}
}