Linux 软件免费装
Banner图

Language Attribute for Container Blocks and Pages/Posts

开发者 nakedcatplugins
webdados
更新时间 2026年6月4日 22:12
PHP版本: 7.2 及以上
WordPress版本: 7.0
版权: GPLv3
版权网址: 版权信息

标签

Gutenberg language accessibility block editor classic editor

下载

3.0 3.1 1.2 2.0 2.1 2.2 1.0 1.1

详情介绍:

This plugin aims to ensure that any language change in a page’s content 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. The plugin also supports setting the language at the page or post level, both on the blocks and the classic editor. When an entire page is written in a different language than the website’s default, you can override the HTML lang and dir attributes for that specific page directly from the Document Settings sidebar, without needing to wrap everything in a container block. For even broader coverage, the plugin supports setting the language at the template level in the Site Editor (Appearance → Editor → Templates). A language set on a template is automatically applied to all pages and posts using that template, unless a specific language is set at the individual post or page level — in which case the post-level setting takes precedence. This plugin is heavily inspired by the Jb Audras plugin (including this readme file). 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 criteria: The purpose of these success criteria is to ensure that user agents can correctly present content written in multiple languages. Keep in mind that you should set the lang and dir attributes only on a container block or page if the content is written in a language different from the one set globally on your website. As per Web Content Accessibility Guidelines: This enables user agents and assistive technologies to present content according to the presentation and pronunciation rules of that language. This applies to graphical browsers, 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 language’s pronunciation rules. Visual browsers can display characters and scripts appropriately. 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.

安装:

  1. Install the plugin and activate it.
  2. To set the language for all pages and posts using a given template: go to Appearance → Editor → Templates, open the desired template, and use the "Template Language" panel in the template settings sidebar.
  3. To set the language for an individual page or post (overriding any template-level setting): open the Document Settings sidebar (the panel icon at the top right of the editor) and use the "Page Language" panel.
  4. To set the language for a specific section within a page: insert a Group, Columns, Cover (or other specific) block, and use the "Block Language" sidebar panel to set the language for all the content inside that container.

屏幕截图:

  • The `lang` and `dir attributes rendered on the frontend
  • Using the highlighting option during the editing process

常见问题:

When should I use the template-level, page-level, or block-level language setting?

Use the Template Language setting (in the Site Editor, under Appearance → Editor → Templates) when you have a group of pages or posts that all share the same language and use the same template — for example, a dedicated template for all your French-language posts. The language set on the template is automatically applied to every page or post using it, so you don't need to configure each one individually. It can always be overridden at the individual post or page level. Use the Page Language setting (in the Document Settings sidebar) when a specific page or post is written in a different language — either overriding the template-level setting or setting it independently when no template language is defined. This overrides the lang attribute on the HTML element itself, which corresponds to WCAG 3.1.1 (Language of Page). Use the Block Language setting (in the block’s sidebar panel) when only a specific section within a page is in a different language, while the rest of the page remains in the site’s default language. This corresponds to WCAG 3.1.2 (Language of Parts).

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.

How can I contribute to this plugin?

On GitHub

How can I report security bugs?

You can report security bugs through the Patchstack Vulnerability Disclosure Program. The Patchstack team helps validate, triage, and handle any security vulnerabilities. Report a security vulnerability.

更新日志:

3.1 - 2026-06-04 3.0 - 2026-03-09 2.2 - 2025-10-20 2.1 - 2025-08-09 2.0 - 2025-08-01 1.2 - 2025-07-25 1.1 1.0