Language Attribute for Container Blocks

Descripción

This plugin aims to provide a way to ensure that any language change in the content of a page is indicated to assistive technologies at the container block level, helping a website comply with WCAG guidelines.

This feature is available on the core block editor only at a text formatting level after code from Jb Audras plugin “Lang Attribute for the Block Editor” was merged into core. The objective of this plugin is to provide the same functionality at a container block level (Group – including all its variants, Columns, Cover, and other specific block types) so that the language applies to all child elements, no matter the kind of content inside.

This plugin is heavily inspired by the Jb Audras plugin (including this readme file), and the development started at WordCamp Europe 2025 Contributor Day, by Marco Almeida from Naked Cat Plugins / Webdados, and the help from Ryan Welcher on the code side and Amber Hinds on the accessibility compliance side.

For more context: this plugin helps you to make your website compliant with the Web Content Accessibility Guidelines (WCAG) success criterion 3.1.2: “Language of Parts”. The purpose of this success Criterion is to ensure that user agents can correctly present content written in multiple languages.

Keep in mind that you should only set the lang and dir attributes to a container block if the content you’re going to insert inside it is written in a different language than that set globally on your website.

As per Web Content Accessibility Guidelines:

This makes it possible for user agents and assistive technologies to present content according to the presentation and pronunciation rules for that language. This applies to graphical browsers as well as screen readers, braille displays, and other voice browsers.

Both assistive technologies and conventional user agents can render text more accurately if the language of each passage of text is identified. Screen readers can use the pronunciation rules of the language of the text. Visual browsers can display characters and scripts in appropriate ways.

This is especially important when switching between languages that read from left to right and languages that read from right to left, or when text is rendered in a language that uses a different alphabet. Users with disabilities who know all the languages used in the Web page will be better able to understand the content when each passage is rendered appropriately.

That’s not just good for accessibility. It’s also great for SEO. Search engines like Google can better understand your content when languages are clearly defined. That means improved indexing and potentially better rankings.

Banner photo by Hannah Wright.

Supported block types

  • Group (core/group): Group contents together and set a language for them
  • Columns (core/columns and core/column): Organize content into a set of columns and set a language for all the columns or a specific column
  • Cover (core/cover): Set the language to all the contents inside a cover block
  • Navigation (core/navigation): Create full navigation menus in different languages
  • Submenu (core/navigation-submenu): Set a different language on a sub-section of your menu (for example, if you have the default language pages on the first level and a sub-menu with pages in another language)
  • Page List (core/page-list): List all the pages on your website that are written in a different language and created as a child of the main page of that language
  • Content (core/post-content): Set the post content on a custom template to a different language

Características

  • Add “lang” and “dir” attributes to Group, Columns, Cover, and other specific WordPress Blocks
  • Show visual outline around blocks that have a language attribute set – For easy identification of blocks you have already set to a different language during your editing process, only for Administrators and Editors, and if enabled in Settings – Writing

Capturas

  • Using the block editor to add a language attribute to a Group block
  • The lang and dir attributes rendered on the frontend
  • Using the highlighting option during the editing process

Instalación

  1. Instala el plugin y actívalo.
  2. Insert a Group, Columns, Cover (or other specific) block, and use the “Language Settings” sidebar panel to set the language for all the content inside that container

FAQ

Why not have the option to set the language attribute on all block types?

The idea is to keep it simple and help content and website editors set different language sections, with as many child-blocks as they want, instead of setting it block by block.

Is it possible to change the highlight color? The default red is not suitable for my website background color.

Yes. Use the nakedcatplugins_lang_attr_highlight_color PHP filter and return the color you want.
Here’s a Gist example.

If your are working on a WordCamp website, or you don’t want to mess around with PHP, you can also add custom CSS to change the color, overriding our --nakedcatplugins-lang-attr-highlight-color variable.
Here’s a Gist example.

¿Cómo puedo contribuir a este plugin?

En GitHub

¿Cómo puedo informar de fallos de seguridad?

Puedes informar de errores de seguridad a través del programa de divulgación de vulnerabilidades de Patchstack. El equipo de Patchstack ayuda a validar, clasificar y manejar cualquier vulnerabilidad de seguridad. Informar de una vulnerabilidad de seguridad.

Reseñas

25 de julio de 2025 1 respuesta
There are many sites that have information on a page in more than one language. When you have entire sections on your page in another language, being able to set the language on those, independent of the main language of the page, is so important. And now we can. Thank you, thank you, thank you, Marco, for making this happen.
Leer la 1 reseña

Colaboradores y desarrolladores

«Language Attribute for Container Blocks» es un software de código abierto. Las siguientes personas han colaborado con este plugin.

Colaboradores

«Language Attribute for Container Blocks» está traducido en 3 idiomas. Gracias a los traductores por sus contribuciones.

Traduce «Language Attribute for Container Blocks» a tu idioma.

¿Interesado en el desarrollo?

Revisa el código , echa un vistazo al repositorio SVN o suscríbete al registro de desarrollo por RSS.

Registro de cambios

2.2 – 2025-10-20

  • [DEV] Implement deployment actions on GitHub
  • [DEV] Update phpcs rules file

2.1 – 2025-08-09

  • [NEW] Support for the Content block type
  • [FIX] Apply the attribute to the correct Group block tag when it’s not a DIV

2.0 – 2025-08-01

  • [NEW] Support for new block types: Navigation, Submenu, and Page List
  • [DEV] Code refactoring: everything now happens inside a class instead of the main plugin file
  • [DEV] Allow changing the highlight color using the nakedcatplugins_lang_attr_highlight_color filter
  • [TWEAK] Better information and screenshot about the highlighting feature for website Administrators and Editors, in the readme.txt file
  • [TWEAK] Make evident that the language shown as a placeholder is the default website language when a custom language is not set for a block

1.2 – 2025-07-25

  • [NEW] Show visual outline around blocks that have a language attribute set – For easy identification, only for Administrators and Editors, and if enabled in Settings > Writing

1.1

  • [Nuevo] Añade compatibilidad con el bloque de fondo
  • [Desarrollo] Descargo de responsabilidad de Patchstack mVDP en el archivo readme.

1.0

  • Primera versión