Emojis break instagram embed
-
Hello all,
This is not as much of a question as it is a bug that I found and how I worked around it. I would love to hear if anyone else has ran into this and if you have a different way of handling it.
So background,
since 3.5, you have been able to embed an instagram photo into a wordpress post just by single lining the instagram link. Example: https://instagram.com/p/tnZ6DfBjly/The problem arises on single.php when the title of that instagram photo has no text, and only emoji’s (as the photo above does). I can inspect the element and i see the alt attribute looks like this:
alt=”
(unclosed double quotes)My solution was to grab a function that would remove all emoji characters from $title which gets echoed into the alt attribute upon runtime.
function removeEmoji($text) {
$clean_text = “”;
// Match Emoticons
$regexEmoticons = ‘/[\x{1F600}-\x{1F64F}]/u’;
$clean_text = preg_replace($regexEmoticons, ”, $text);
// Match Miscellaneous Symbols and Pictographs
$regexSymbols = ‘/[\x{1F300}-\x{1F5FF}]/u’;
$clean_text = preg_replace($regexSymbols, ”, $clean_text);
// Match Transport And Map Symbols
$regexTransport = ‘/[\x{1F680}-\x{1F6FF}]/u’;
$clean_text = preg_replace($regexTransport, ”, $clean_text);
// Match Miscellaneous Symbols
$regexMisc = ‘/[\x{2600}-\x{26FF}]/u’;
$clean_text = preg_replace($regexMisc, ”, $clean_text);
// Match Dingbats
$regexDingbats = ‘/[\x{2700}-\x{27BF}]/u’;
$clean_text = preg_replace($regexDingbats, ”, $clean_text);
return $clean_text;
}
credit: https://stackoverflow.com/questions/12807176/php-writing-a-simple-removeemoji-functionI added that function to the bottom of wp-includes/class-oembed.php
and added $title = removeEmoji($title); to line 512 of the same fileI tested the same photo afterwards and the alt attribute was empty and the post was no longer breaking.
Hope this helps someone else in the future.
- The topic ‘Emojis break instagram embed’ is closed to new replies.