I am trying to use the http://www.tinymce.com/ plugin to add a tinymce to my textareas in my meta boxes I have created. I’ve googled other ways and either I cant get it to work or didnt grasp the concept. SO this is what Im trying now —
I tried creating plugin to add the script to my admin dashboard —
add_action('admin_init', 'admin_load_scripts');
function admin_load_scripts() {
$js_file = plugins_url( '/tinymce/jquery.tinymce.min.js', __FILE__ );
wp_enqueue_script('jquery.tinymce.min', $js_file, array('jquery'));
}
Then I need to call it like so —
<script>
tinymce.init({selector:'textarea'});
</script>
But im not sure how to do this, being that this is for the backend and not the front end.
How can I achieve this?
UPDATED
This is my code for the meta boxes.
http://pastebin.com/WcC51uA9
I tried the following methods (placing it in functions.php of course), and for the most part they either just didnt work or would show up on the top of the page or on the bottom of the page. They didnt show up on the textarea at all. —
http://pastebin.com/Ct0mF6q7
http://pastebin.com/R6t0ij6h
http://pastebin.com/dcczcVby
http://pastebin.com/yt1uRS5U
3 s
Here’s a pastebin with your code included.
Get the old value of the tinyMCE
$meta_biography = get_post_meta( $post->ID, 'meta_biography', true );
Call the TinyMCE Editor
wp_editor( $meta_biography, 'biography', array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'meta_biography',
'textarea_rows' => 10,
'teeny' => true
) );
Save The Editor Value or if nothing is there – delete old values.
if( isset( $_POST['meta_biography'] ) && $_POST['meta_biography'] != '' ) {
update_post_meta( $post_id, 'meta_biography', $_POST['meta_biography'] );
} else {
delete_post_meta( $post_id, 'meta_biography' );
}
If you want to add more options to the editor – You can view the Codex or Check out this nice WPTuts Article. You want to use the tinymce
and pass it an array of settings. You might have to remove the teeny => true
in the wp_editor()
since the Codex says that it will only use minimal editor configuration.