Add tinymce editor to wordpress form’s textarea field

Just make sure to use the id of the textarea you want to select in the elements: “elm1,elem2” variable.
Assuming you have a textarea with the id of ‘elm1’ and ‘elem2’:
Put the following code into your functions.php of your theme file or you can use it on your plugin

<?php
// hook into WordPress
	add_action('wp_head', 'javascript_on_header' );

function javascript_on_header () {
    wp_enqueue_script('tiny_mce');?>

<script type="text/javascript">
		tinyMCE.init({
			mode : "exact",
			elements : "elm1,elem2", //putting extra tetarea id seperated by comma to show WYSIWYG 
			//theme : "simple",
			theme : "advanced",
			   height:"250",
				//width:"600",

			// Theme options
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,| formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons3 : "", 
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,

		});
	</script>

<?php }?>

And the form should look like this.

<form method="post" action="">
<ul>
  
  <li><textarea style="width:100%;" class="tinymce_data" id="elm1" name="tinymce_data1"></textarea></li>
<li><textarea style="width:100%;" class="tinymce_data" id=" elem2" name="tinymce_data2"></textarea></li>
</ul>
</form>

Comments

comments

4 Comment

  1. Its really great thing which is given here by you and I am much impressed by your knowledge.
    Thanks to share it here.

  2. yami says: Reply

    not working

  3. ifurlo says: Reply

    Hi, i following your guide and wordpress say:
    Parse error: syntax error, unexpected ‘<' in /hermes/bosweb/web096/b960/MyServer/MyWordpress/wp-content/themes/ThemesName/functions.php on line 402

    Have you idea?

    Tank in Advance

  4. Nice Info,.,.
    thanks,.,.

Leave a Reply