• Resolved adamohern

    (@adamohern)


    Hey everybody, thanks for the fantastic forum. It’s invaluable!

    I’m struggling to get WP to output literal HTML special characters. The most bizarre thing is that it seems to actively decode properly escaped characters. Take the following example:

    function test_htmlspecialchars($content){
        return htmlspecialchars('<a href="#">Link</a>');
    }
    add_action('the_content','test_htmlspecialchars');

    The filter should replace the_content() with escaped special characters, which, in the browser, should render as copy/paste friendly html. Weirdly, however, it seems that WP is taking the character codes like ‘-&-l-t-; (hyphens added to hack the forum) and decoding them, resulting in a literal ‘<‘ character.

    Does anyone know how to keep this from happening? I’ve experimented with everything I can find–wpautop, hooks, actions, bla bla bla–and I can’t seem to lick this thing. Any help greatly appreciated!

    EDIT: HA! Irony of ironies, publishing this very post (here on www.remarpro.com) just automatically converted my special characters to literal html. I feel like I’m taking crazy pills! Edited the code above, adding the “htmlspecialchars” function since I can’t get it to display the character codes inline ??

Viewing 1 replies (of 1 total)
  • Thread Starter adamohern

    (@adamohern)

    Oh shucks. It seems to be something to do with the custom theme I’m using, as disabling the theme makes things work as expected. Drat. Sorry folks, thanks anyway.

Viewing 1 replies (of 1 total)
  • The topic ‘htmlspecialchars not working in filters for the_content?’ is closed to new replies.