Is there a filter for allowing HTML / Javascript into a custom field textarea? I'm using get_post_meta.

On the frontpage I want the HTML / Javascript to run, not to be displayed.

  • Can you give and example of what your trying to run or is it a general question ?
    – Sagive
    Commented Oct 24, 2011 at 4:15

4 Answers 4


The correct answer is esc_textarea().


<textarea><?php echo esc_textarea($whatever); ?></textarea>

I answered an identical question earlier today HERE which tackled the same issue. In the case where you don't want to use a plugin like that suggested by EarnestoDev, you can simply wrap the output of your <textarea></textarea> with PHP's htmlspecialchars function like so;

<textarea name="my_html">

      <?php echo htmlspecialchars($content); ?>


Regardless of whether its a textarea or an input field etc, you still need to wrap your input in htmlspecialchars to preserve your tags from being stripped.

  • 1
    Don't do that. Use the built in functions. The esc_textarea() function is what you want for this case. If he wanted to put something in an attribute (like the value field of an input tag), then he would use esc_attr() instead.
    – Otto
    Commented Jul 7, 2012 at 21:54
  • For a WP based function, yes esc_textarea is the API call you want to be making and what I should have said in context was htmlspecialchars which is what underpins esc_textarea. So to the OP, use esc_textarea instead, although using htmlspecialchars is perfectly valid PHP, its not the official API call, regardless of whether it'll do you no harm, at the very least you gain an insight to what esc_textarea is using, should you venture outside of the WP platform. htmlentities is also valid but its use-case dependent and probably not in context. @Otto I'll am mend my other answer.
    – Adam
    Commented Jul 8, 2012 at 1:00

Use the plugin I posted here: Problem with <code> tag .

Does what you need and more!


Yes, there must be. When you save this into a custom field with a key let's say "test"...


You will get Test1Test2 when you run...

echo get_post_meta($post->ID, 'test', true);

If I knew which filter was responsible for this I'd just do a remove_filter(). It would be great if there was a plugin that would show you what filters are registered to a specific hook. (There is a get_post_meta hook defined in /wp-includes/meta.php)

  • Actually, I believe the html is being stripped out before it's saved to the database, not while it is being pulled out.
    – Andrej
    Commented Jan 13, 2012 at 19:25

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.