Skip to content

Trouble with textarea in TinyMCE Editor

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.

Published inWordPress

4 Comments

  1. Shirish Shirish

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

Leave a Reply

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