Skip to content

Commit

Permalink
Prevent screen readers from reading the arrow emoji in content (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle authored Aug 16, 2023
1 parent 2a4abba commit 9602535
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/wp-content/themes/wporg-parent-2021/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
add_action( 'after_setup_theme', __NAMESPACE__ . '\theme_support', 9 );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
add_filter( 'author_link', __NAMESPACE__ . '\use_wporg_profile_for_author_link', 10, 3 );
add_filter( 'render_block_core/pattern', __NAMESPACE__ . '\add_aria_hidden_to_arrows', 19 );
add_filter( 'the_content', __NAMESPACE__ . '\add_aria_hidden_to_arrows', 19 );
add_filter( 'render_block_core/pattern', __NAMESPACE__ . '\prevent_arrow_emoji', 20 );
add_filter( 'the_content', __NAMESPACE__ . '\prevent_arrow_emoji', 20 );
add_filter( 'wp_theme_json_data_theme', __NAMESPACE__ . '\merge_parent_child_theme_json' );
Expand Down Expand Up @@ -94,6 +96,20 @@ function use_wporg_profile_for_author_link( $link, $author_id, $author_nicename
);
}

/**
* Wrap the arrow emoji in an aria-hidden span tag, to prevent screen readers
* from trying to read them.
*
* This runs just before `prevent_arrow_emoji`, so that the variation-selector
* can be added inside the span.
*
* @param string $content Content of the current post.
* @return string The updated content.
*/
function add_aria_hidden_to_arrows( $content ) {
return preg_replace( '/([←↑→↓↔↕↖↗↘↙])/u', '<span aria-hidden="true">\1</span>', $content );
}

/**
* Add the variation-selector unicode character to any arrow. This will force
* the twemoji script to skip these characters, leaving them as text.
Expand Down

0 comments on commit 9602535

Please sign in to comment.