0

I have a private plugin that exports all posts without 'themeing', so the output is just html of the content (with the post subject as H1, and date/time as H2).

If a post contains an emoji, it is displayed properly on a themed page. But if I save the HTML output to a file, the emoji comes out something like

🙁 

These are UniCode character (I think), and I need the generated HTML page to show the emoji as a graphic image.

My code that creates the HTML output uses a standard WP_Query object, then outputs the_content within the have_posts loop:

$thestring .= apply_filters('the_content',$post->post_content) // keep adding the content to $thestring

The $thestring variable, which contains all posts content, is then added to an HTML document, and that is output to a HTML file.

When I load the HTML file into the browser, the emoji is shown as something like 🙠. If I load the HTML file into Word 2010 (so I can convert the blog content into a Word document), it also shows up as 🙠.

How do I get the emoji content in the HTML file into a graphic? Is there some library I need to load via the plugin, or some conversion function? Again, the ultimate goal is to get all blog content into a Word document.

Update

I believe the problem is that my plugin is not loading some functions/JS that is used when a template is applied to the page. The template uses the the_content() function in the loop to output the posts. The template will output the emoji images properly.

But if I take the same loop that the template uses and use it in my plugin, the emoji images are not displayed. Any apply_filter to the_content does not matter; the plugin code will not display the emoji graphics. Only the template (applied to a page) will show emoji graphics.

So, the question might be restated as: what functions/includes are used in the page template that I need to add to my plugin?

1
  • does the emoji show properly on the html output page when the_content filter isn't applied? Aug 5, 2018 at 6:20

1 Answer 1

0

To have your emoji characters displayed correctly, your html document MUST HAVE this meta in the header:

<meta charset="UTF-8">

To insert emoji character into your content, you can ether copy/paste it, or use its numerical code. This will be a code for a hamburger: &#x1F354; resulting this: 🍔.

Update

It looks like your wp_posts table's collation belongs to 'utf8_' group. To correctly store emoji characters, your wp_posts table's collation must be one of 'utf8mb4_' group. If it's not, change it with phpMyAdmin, edit, and update your posts.

4
  • That is already in the generated HTML output. I suspect it is some JS or other 'load' that I am not doing in the plugin that is in a template. Aug 5, 2018 at 1:18
  • Please read the update to my answer. Aug 5, 2018 at 3:14
  • I note that the posts, when displayed by the theme/template, shows all emojis properly. So I assume that to mean that the emojis are being stored properly, since they are displayed when viewing the post. Aug 5, 2018 at 4:33
  • I cannot replicate this problem. I've followed your procedure and created HTML file. When I run it locally, or on the server, it shows emoji characters correctly. In your case, malformed emoji might suggest that HTML file was saved with encoding different from UTF-8. Try to check your resulting HTML for encoding type. Aug 6, 2018 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.