Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Header/Footer: Hide the arrow emoji for screen reader users #454

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mu-plugins/blocks/global-header-footer/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
add_filter( 'style_loader_src', __NAMESPACE__ . '\update_google_fonts_url', 10, 2 );
add_filter( 'render_block_core/navigation-link', __NAMESPACE__ . '\swap_submenu_arrow_svg' );
add_filter( 'render_block_core/search', __NAMESPACE__ . '\swap_header_search_action', 10, 2 );
add_filter( 'render_block_wporg/global-header', __NAMESPACE__ . '\add_aria_hidden_to_arrows', 19 );
add_filter( 'render_block_wporg/global-footer', __NAMESPACE__ . '\add_aria_hidden_to_arrows', 19 );
add_filter( 'render_block_data', __NAMESPACE__ . '\update_block_style_colors' );

/**
Expand Down Expand Up @@ -998,6 +1000,17 @@ function swap_header_search_action( $block_content, $block ) {
return $block_content;
}

/**
* Wrap the arrow emoji in an aria-hidden span tag, to prevent screen readers
* from trying to read them.
*
* @param string $content Content of the block.
* @return string The updated content.
*/
function add_aria_hidden_to_arrows( $content ) {
return preg_replace( '/([←↑→↓↔↕↖↗↘↙])/u', '<span aria-hidden="true">\1</span>', $content );
}

/**
* Translate the tagline with the necessary text domain.
*/
Expand Down