Call TinyMCE in a WordPress plugin Call TinyMCE in a WordPress plugin wordpress wordpress

Call TinyMCE in a WordPress plugin


This is much easier to do in WordPress 3.3 using the wp_editor() function.

I'm working on a plugin that will add a TinyMCE instance to a theme options page. Here's what it looks like:

// Add TinyMCE visual editorwp_editor( $content, $id );

Where $content is the stored content and $id is the name of the field. Options can also be passed to customize the TinyMCE functionality, check out the WordPress Codex for more details.


Camden already answered this, but in case somebody needs the full code... Be sure to hook in admin_head, hooking into admin_enqueue_scripts will cause it to load before other scripts, such as jQuery, so it will not work.

add_action("admin_head","load_custom_wp_tiny_mce");function load_custom_wp_tiny_mce() {if (function_exists('wp_tiny_mce')) {  add_filter('teeny_mce_before_init', create_function('$a', '    $a["theme"] = "advanced";    $a["skin"] = "wp_theme";    $a["height"] = "200";    $a["width"] = "800";    $a["onpageload"] = "";    $a["mode"] = "exact";    $a["elements"] = "intro";    $a["editor_selector"] = "mceEditor";    $a["plugins"] = "safari,inlinepopups,spellchecker";    $a["forced_root_block"] = false;    $a["force_br_newlines"] = true;    $a["force_p_newlines"] = false;    $a["convert_newlines_to_brs"] = true;    return $a;')); wp_tiny_mce(true);}}

Then somewhere in your template insert a regular textarea:

<textarea id="intro"></textarea>


The following example works for me. Just make sure to use the id of the textarea you want to select in the $a["elements"] variable.

Assuming you have a textarea with the id of 'intro':

// attach the tiny mce editor to this textareaif (function_exists('wp_tiny_mce')) {  add_filter('teeny_mce_before_init', create_function('$a', '    $a["theme"] = "advanced";    $a["skin"] = "wp_theme";    $a["height"] = "200";    $a["width"] = "800";    $a["onpageload"] = "";    $a["mode"] = "exact";    $a["elements"] = "intro";    $a["editor_selector"] = "mceEditor";    $a["plugins"] = "safari,inlinepopups,spellchecker";    $a["forced_root_block"] = false;    $a["force_br_newlines"] = true;    $a["force_p_newlines"] = false;    $a["convert_newlines_to_brs"] = true;    return $a;')); wp_tiny_mce(true);}

?>