Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 14:00 9:00 – 14:00 9:00 – 14:00 9:00 – 14:00 9:00 – 14:00 -
- 15:00 – 18:00 15:00 – 18:00 15:00 – 18:00 15:00 – 18:00 15:00 – 18:00 -

Supporter timezone: Asia/Dhaka (GMT+06:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Prosenjit Barman 2 days, 5 hours ago.

Assisted by: Prosenjit Barman.

Author Posts
October 1, 2024 at 3:11 pm #16241530

Mason Grandusky

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?

October 2, 2024 at 5:47 am #16243341

Prosenjit Barman
Supporter

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hello There,
I hope you're doing well.

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.

Best regards,
Prosenjit