Make emoji more accessible.
Add this package with composer:
composer require jonnybarnes/emoji-a11y
Anywhere you have some text with emoji use the makeEmojiAccessible
method.
$emoji = new Jonnybarnes\EmojiA11y\EmojiModifier();
$text = 'Iโm ๐';
$emoji->makeEmojiAccessible($text); // Iโm <span role="img" aria-label="grinning face">๐</span>
You can pass in a string to the constructor that will be used in the
makeEmojiAccessible
method. We use PHPโs sprinf
function.
Three variables are passed into the function. The desired output form, then the
text of the emoji, then the matched emoji character. Thankfully sprintf
allows
you to swap variable order if you need to, see example 3 in the manual.
Of course you need to provide your own CSS for presentation.
Inspired by http://adrianroselli.com/2016/12/accessible-emoji-tweaked.html