I am having a problem with how WP handles content in the Visual vs. Text editor views. This has been very thoroughly discussed here and here, but my situation is not quite addressed:

If I enter a special character in the Visual tab, like an em-dash or curly quotes, they remain just the same in the Text tab... i.e. NOT converted to &emdash; or “ and while that displays OK on the site, I send some pages via a mailing list program - Dada Mail - which expects proper HTML code, something it evidently doesn't get in these cases. The result is a lot of "Â", and other weird characters, in the resulting email. Sometimes this even happens around simple things like a period, if it's been pasted in from another program.

I guess what I really am asking for is a way to convert these special characters into their corresponding HTML automatically. Or, at least, when the user clicks the Text tab or something. I have searched for a plugin that might achieve this, but all I find are ones that go the other way - they preserve HTML already entered in on the Text side. My clients generally won't be using that side, or dealing with any HTML, and I don't want them to have to. But this glitchy-character issue keeps rearing its ugly head when they want to send a mailout.

[EDIT] Looking deeper into this, it looks like a modification to the behaviour of the TinyMCE editor might be all I need. I have looked at the codex article about TinyMCE, but I'm stuck - is there an option to achieve this sort of behaviour? I.E. convert typed special characters (or at least the most common ones, like curly quotes and em-dashes) to HTML entities?

  • How are you inserting your content into emails? WordPress does the conversion on display via filters hooked to the_content() function.
    – Milo
    Commented Dec 14, 2017 at 4:44
  • My email software grabs a web page and sends it - and it's evidently stricter /more finicky than the browser is about encoding. Things that look fine in the browser often become garbled characters when viewed in the resulting email. If - for example - a curly quote did not display as a curly quote in the code (as it now does) but as ’, I think the glitches would not happen. Commented Dec 14, 2017 at 6:50
  • I feel like I'm getting closer by modifying a TinyMCE setting with a function: function myformatTinyMCE($in) { $in['entity_encoding']= 'numeric'; return $in; } add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' ); This preserves HTML entities on the Text tab... however, whatever I set "entity_encoding" to, it stops displaying things visually on the Visual tab. It only shows the code there too - plus, it's white on white! Not good. Am i getting close....? Commented Dec 14, 2017 at 20:36
  • I really don’t think the solution has anything to do with tinymce, as WP is doing the conversion into HTML entities on output, not in the editor. I would first verify that your template is using the_content correctly with all its filters intact.
    – Milo
    Commented Dec 14, 2017 at 23:51
  • Hmm, well I'm not doing anything (so far) other than a standard call to the_content in my template. I found a plugin that essentially uses this code to do a string replacement. I modified it to use the second code block on that page, i.e. to replace with HTML entities... but in the editor AND on the page, the ‘ etc. codes are still converted to visually-displayed characters and the explicit entities are lost. I'd like to prevent that... Commented Dec 15, 2017 at 17:41


Your Answer

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

Browse other questions tagged or ask your own question.