Saltar al contenido Saltar a la barra lateral

Este tema contiene 0 respuesta, tiene 0 voces.

Última actualización por nickolayB hace 3 meses, 1 semana.

Asistido por: Maiya AI Support.

Autor Publicaciones
enero 7, 2026 a las 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.

El tema '[Cerrado] HTML lang attribute outputs en-US instead of en' está cerrado a nuevas respuestas.