The Aria Labels plugin is designed to enhance accessibility on your WordPress website by adding aria-hidden and aria-label attributes to Gutenberg blocks. This version is maintained by Sunny Morgan and is based on the original plugin by Jacob Lodes.
- Adds
aria-hiddenandaria-labelattributes to Gutenberg blocks to improve accessibility. - Enhances core accessibility by applying the
aria-labelto the correct interactive element within a block (e.g., the<a>tag inside a button block), which is more effective than the default behavior. - Automatically adds
aria-hidden="true"to decorative images (image blocks with an empty alt attribute). - Works seamlessly with WordPress 6.8+ by hiding its own
aria-labelcontrol when native support is present, preventing a confusing user interface. - Provides a settings panel in the block editor, which can be moved to the "Advanced" accordion for a cleaner UI.
- Allows developers to configure which blocks the controls appear on via a PHP filter.
- The plugin can be updated directly from GitHub using the
Updaterclass.
- After installing and activating the plugin, controls for "Aria Hidden" and "Aria Label" will appear in the block inspector for supported blocks.
- Download the latest release of the plugin from the GitHub repository.
- Log in to your WordPress admin dashboard.
- Navigate to Plugins > Add New.
- Click on the "Upload Plugin" button at the top of the page.
- Click "Choose File" and select the downloaded zip file.
- Click "Install Now" and then "Activate Plugin".
- After pushing your code changes, you must create a new Release on GitHub.
- The Tag version for the release must be higher than the plugin's current version number (e.g.,
2.0.5is higher than2.0.4). - Once the release is published, log in to your WordPress admin dashboard.
- Go to Dashboard > Updates and click "Check Again" to force an immediate check.
- You will then see the update notification on the Plugins page.
This section contains information for developers who want to contribute to the plugin or understand its structure for maintenance purposes.
- File Structure: The main plugin file is
aria-labels.php. Theincludesdirectory contains the PHP classes for each feature. Theadmindirectory contains the code for the admin interface. - Key Classes: The
Aria_Attributesclass inincludes/class-aria-attributes.phphandles all server-side logic, including adding user-defined ARIA attributes and automatically handling attributes for decorative images. TheUpdaterclass inincludes/class-updater.phphandles updates to the plugin. - The
Aria_Attributesclass uses theenqueue_block_editor_assetsaction to enqueue the JavaScript file in the Gutenberg editor and therender_blockfilter to modify the block's final HTML. - The
Updaterclass uses the GitHub API to fetch the latest release of the plugin and update it if necessary. It also adds details to the plugin popup and modifies the transient before updating plugins.
This section contains documentation for configuring the Aria Labels plugin.
You can customize the plugin's behavior by using the aria_labels_settings filter in your theme's functions.php or a custom plugin.
Example:
add_filter( 'aria_labels_settings', function( $settings ) {
// Move the controls out of the 'Advanced' panel and into their own panel.
$settings['moveToAdvanced'] = false;
// Add the 'core/list' block to the allowed list.
$settings['allowedBlocks'][] = 'core/list';
// Remove the 'core/image' block from the list.
$settings['allowedBlocks'] = array_filter(
$settings['allowedBlocks'],
function( $block_name ) {
return 'core/image' !== $block_name;
}
);
return $settings;
} );