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?


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');
  • Please post more code. How does this plugin work? Is it hooked to the_content maybe? – s_ha_dum Feb 11 '13 at 19:33
  • Yes, I'm hooking the_content. I've edited the question to provide more info. – flashk Feb 11 '13 at 20:01

Add a priority to push your function to the end of the hook queue.

add_action('the_content', 'my_plugin_content_hook', 1000);

Then, in your get_special_content function you will need to apply wpautop manually to the content to which you want it applied.

function get_special_content()
    $text = '';
    $autopeed = 'content to autop';
    $text .= apply_filters('wpautop',$autopeed);
    $text .= "your textarea code";
    return $text;

I believe that will solve your problem.

  • Thanks, that worked. However, I found a simpler solution and posted it as well. – flashk Feb 13 '13 at 17:31

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.

echo '<pre><textarea>'.esc_textarea($message).'</textarea></pre>';

I'm not sure why wpautop doesn't also ignore <textarea> tags by default. I can't imagine a scenario where you would want wpautop to be applied to the contents of a text area. Maybe it's just an oversight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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