I’m using the following code in my plugin to display a <textarea>
field on a page:
echo '<textarea required="required" name="Message" class="textarea" cols="70" rows="10">'.esc_textarea($message).'</textarea>';
However, WordPress seems to be inserting <p>
and <br />
tags into the textarea contents if the message contains newline characters. I’m assuming this is being caused by the default wpautop() filter.
Is there a way to disable filtering of <textarea>
contents on a page?
Edit
Some more information about how my plugin works. It creates a hook for the_content
, which will append data to the contents of certain pages. I still want wpautop
formatting to be applied to the appended content, just not for the <textarea>
field.
Here is a rough outline of how my plugin is setup:
function get_special_content()
{
$text = '';
// Customized content is appended to text here
// including the textarea field
return $text;
}
function my_plugin_content_hook($content)
{
if(is_some_special_page()) {
return $content.get_special_content();
}
return $content;
}
add_action('the_content', 'my_plugin_content_hook');
Add a priority to push your function to the end of the hook queue.
Then, in your
get_special_content
function you will need to applywpautop
manually to the content to which you want it applied.I believe that will solve your problem.
I discovered that
wpautop
will preserve the contents of<pre>
tags. By placing a<pre>
tag around the<textarea>
tag, I am able to prevent the text area contents from being modified.I’m not sure why
wpautop
doesn’t also ignore<textarea>
tags by default. I can’t imagine a scenario where you would wantwpautop
to be applied to the contents of a text area. Maybe it’s just an oversight.