Перейти к содержимому Перейти к боковой панели

Эта тема содержит 0 ответ, имеет 0 голосов.

Последнее обновление: nickolayB 3 месяца, 1 неделя назад.

При содействии: Maiya AI Support.

Автор Сообщения
07.01.2026 в 09:19 #17708741

nickolayB

Hello WPML Support Team,

We are using WordPress with WPML and WooCommerce (2 languages).
By default, in the site markup we have: <html >

This outputs:

From an SEO perspective, we need the HTML attribute to be:

We checked WPML language settings and only see the following options:
Language name
Code
Translation
Flag
Default locale
Encode URLs
hreflang
Language mapping

We do not see any option that allows changing the output from en-US to en.

Could you please confirm:
Is there an official WPML setting or a recommended approach to output lang="en" instead of lang="en-US"?
If there is no built-in option, is it acceptable and safe to override this behavior at the theme level using the language_attributes filter?

We see that this can be achieved with the following filter:
add_filter( 'language_attributes', function ( $output ) {
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
$output = preg_replace(
'/lang="[^"]+"/',
'lang="' . esc_attr( ICL_LANGUAGE_CODE ) . '"',
$output
);
}
return $output;
}, 99 );

Could this approach have any negative impact on WPML functionality, language handling, or SEO-related features such as hreflang?

Thank you in advance for your clarification.

Тема '[Закрытые] HTML lang attribute outputs en-US instead of en' закрыта для новых ответов.