Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Can you give and example of what your trying to run or is it a general question ? –  Sagive SEO Oct 24 '11 at 4:15

4 Answers 4

The correct answer is esc_textarea().

Example:

<textarea><?php echo esc_textarea($whatever); ?></textarea>
share|improve this answer

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); ?>

</textarea>

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.

share|improve this answer
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 Jul 7 '12 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. –  userabuser Jul 8 '12 at 1:00

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

Does what you need and more!

share|improve this answer

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

<p>Test1</p><p>Test2</p>

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)

share|improve this answer
    
Actually, I believe the html is being stripped out before it's saved to the database, not while it is being pulled out. –  Andrej Jan 13 '12 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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