Posted by & filed under WordPress.

Came across an issue where the TinyMCE editor inside WordPress was stripping out <textarea> tags as I switched between the HTML and Visual editors, and the page I was working on needed a textarea.

After digging through Google I came across a pretty good reason. A textarea inside another textarea can cause problems so they’re not allowed. Makes sense, but not really a solution.

What I did was add a bit of code to my theme functions.php file to create a pseudo shortcode.

function allow_textareas($content) {
	return preg_replace(
		'/\[\s*textarea(.*?)\](.*)\[\s*\/textarea\]/i',
		'<textarea$1>$2</textarea>',
		$content);
}
add_filter('the_content','allow_textareas');

It’s not really a true short code, but it does work. And I didn’t want to do an actual short code because I would have to worry about the different possible attributes. Regex allowed me to just replace what I needed to and leave the rest.

Now all I have to do is [textarea][/textarea] and the function takes care of replacing it with the right HTML tags.

4 Responses to “Trouble with textarea in TinyMCE Editor”

  1. Alma

    This worked beautifully for me. I had searched everywhere online to get the textarea to work. Thanks so much for this!

    Reply
  2. Shirish

    I am facing same issue, but I didn’t found functions.php file in tinymce folder .

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *