janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Emoji in post titles (maybe bug? maybe my fault? maybe a feature request?) #45

Closed djwudi closed 1 year ago

djwudi commented 1 year ago

I just got this installed and working, but have discovered a minor issue — I use emoji in my blog post titles, but they seem to be getting mangled and are instead just appearing in the Mastodon post as the raw HTML entity and partially turned into a Mastodon tag.

Example:

I'm not sure if this is a bug somewhere in the plugin, a bug of my own making in the PHP code I came up with for making the Mastodon post look the way I want, or if this is just something that could be resolved in a future update.

Any assistance would be appreciated! Thanks!

janboddez commented 1 year ago

I think get_the_title() returns HTML-encoded emoji (and quotes, and so on). And Mastodon then escapes that code, i.e., turns the literal & into &.

Looking at the source code of your website: image

What might help is decode entities back to "raw" Unicode, so use html_entity_decode( get_the_title( $post ) ). Or better still, just unescape the whole thing just before returning it: return html_entity_decode( $status ).

Depending on your site's character encoding, you may need to pass a 2nd and 3rd parameter to html_entity_decode(), but 9 times out of 10 this is enough.

janboddez commented 1 year ago

Just thought I'd have to fix this in the plugin itself, too, but behold :-): https://github.com/janboddez/share-on-mastodon/blob/7b2e5b4edc44df8280086edf3fe2657e80522fab/includes/class-post-handler.php#L327

djwudi commented 1 year ago

Thanks so much, Jan! The single-line fix of adding return html_entity_decode( $status ) did the trick. Thanks for the quick and on-point response!