How to add wysiwyg editor in Wordpress meta box How to add wysiwyg editor in Wordpress meta box wordpress wordpress

How to add wysiwyg editor in Wordpress meta box


Here is full code example:

add_action( 'add_meta_boxes',  function() {     add_meta_box('html_myid_61_section', 'TITLEEEEE', 'my_output_function');});function my_output_function( $post ) {    $text= get_post_meta($post, 'SMTH_METANAME' , true );    wp_editor( htmlspecialchars($text), 'mettaabox_ID', $settings = array('textarea_name'=>'MyInputNAME') );}add_action( 'save_post', function($post_id) {    if (!empty($_POST['MyInputNAME'])) {        $datta=sanitize_text_field($_POST['MyInputNAME']);        update_post_meta($post_id, 'SMTH_METANAME', $datta );    }}); 

P.S. MUST-Recommendation from my experience:

Forget adding custom codes, use Advanced Custom Fields, it's excellent and simplify your life.


http://codex.wordpress.org/Function_Reference/wp_editor was by far the easiest method I found, built into Wordpress since 3.3 (so upgrade ;-) )


But you need to replace presentation with nl2br() function as textarea in custom templates have the toogle JS issue, that removes all your <P> and <br/> tags and therefore all line breaks.