• I created a custom meta box with a textarea to input text but am wondering if there’s a way prevent WordPress from ignoring special characters, breaks, etc. in that custom field when I save the post. For example, if I type a double dash or use the &emdash; code, nothing is done with it when the field is output to a page. It just shows up as a double dash or ” &emdash; ” in the text. What I want to see is the actual em dash!

    If anyone can point me in the right direction, I’d appreciate it.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Consider granting users that need this functionality ‘unfiltered_html’ capability, that may be all that’s needed. If that doesn’t work, continue…

    WP filters form data through various functions intended to protect the site from unsophisticated or malicious users. It’s possible to track down these filters and remove them, just be sure you don’t remove security functions, otherwise someone could actually do bad things to your site and/or your readers through the meta box.

    I believe one of these functions is htmlentities() (or maybe htmlspecialchars()), on output you could simply reverse these functions with html_entity_decode() or similar. Alternately, simply enter the emdash character or whatever directly, instead of trying to encode it. Then the filter function will encode it for you and the output will appear correctly without further intervention.

    Yes, one cannot type an emdash character from most keyboards. One could make up a word processing document with such characters from which they can copy/paste, or simply compose the content in a word processor, then paste the entire thing into the metabox. Sort of a pain, but it may be preferable to hacking WP and possibly introducing security vulnerabilities.

Viewing 1 replies (of 1 total)
  • The topic ‘allow HTML and special characters in custom meta box’ is closed to new replies.