Background of the issue:
We setup our hreflang tag to zh-Hans but on loading of the page it renders as zh-hans. We need the H in Hans to be capital as recommended by both Google and SEMRush.
Symptoms:
The hreflang tag renders as zh-hans instead of zh-Hans.
Questions:
How can we ensure the hreflang tag renders with a capital H in Hans as zh-Hans?
I reviewed the entire conversation you had with my colleague and identified the issue. The reason the `hreflang` code appears in lowercase is due to how WPML processes language codes internally. WPML normalizes the `hreflang` language codes to lowercase during output, which is typically done for consistency or technical reasons.
If you want the 'h' in 'zh-hans' to appear in a capitalized form, you'll need to use a custom coding approach. A code similar to the example below may help in displaying the 'h' as capitalized.
add_action('template_redirect', 'start_output_buffer');
function start_output_buffer() {
ob_start('modify_hreflang_output');
}
function modify_hreflang_output($buffer) {
$buffer = str_replace('hreflang="zh-hans"', 'hreflang="zh-Hans"', $buffer);
return $buffer;
}
Although providing support for custom coding is beyond the scope of our support, I'm sharing the code to demonstrate the process. If you need further assistance with custom coding, consider hiring a developer specializing in WPML customizations from here: https://wpml.org/contractors
I hope you can understand. Feel free to let me know if you have any other questions or need clarification. I'll be happy to help.