Custom wp_editor | WordPress.org

Can you show us the code that you’re using? Start off with where you’re outputting the content as that seems to be where the problem is at the moment.

This are my codes in function.php

add_action( 'add_meta_boxes', 'post_note_meta_box_add' );
function post_note_meta_box_add()
{	
	// Add new meta box
	add_meta_box( '_post_note', 'Html Box', 'render_post_note_meta_box', 'urunler', 'normal', 'high' 
                );
}

function render_post_note_meta_box()
{
	global $post;
	// Get saved meta data
	$post_note_meta_content = get_post_meta($post->ID, '_post_note', TRUE); 
	if (!$post_note_meta_content) $post_note_meta_content = '';
	wp_nonce_field( 'post_note'.$post->ID, 'post_note_nonce');
	// Render editor meta box
	wp_editor( $post_note_meta_content, 'post_note', array('textarea_rows' => '5'));
}

add_action( 'save_post', 'post_note_meta_box_save' );
function post_note_meta_box_save( $post_id )
{
    
   
    
	// Bail if we're doing an auto save
	if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
	 
	// if our nonce isn't there, or we can't verify it, bail
	if( !isset( $_POST['post_note_nonce'] ) || !wp_verify_nonce( $_POST['post_note_nonce'], 'post_note'.$post_id ) ) return;
	 
	// if our current user can't edit this post, bail
	if( !current_user_can( 'edit_post' ) ) return;
	
	
	// Make sure our data is set before trying to save it
	if( isset( $_POST['post_note'] ) )
		$result = update_post_meta( $post_id, '_post_note', $_POST['post_note']) ;
    }

And this is my code in html page

 <div class="tab-pane" id="3">
    
               <?php  
               
               
               
  
    $meta_value = get_post_meta($post->ID, '_post_note',true);
    
   $meta_value = str_replace( ']]>', ']]>', $meta_value );
    

 echo $meta_value;
    ?>
            
				</div>

My html soure in chrome

<div class="tab-pane active show" id="3">
    
               2222

&nbsp;

Test

&nbsp;

&nbsp;

Value            
				</div>

Thank you

  • This reply was modified 3 days, 20 hours ago by Hakan.

The PHP code for your template is always going to output the content without any formatting because you’re not actually doing anything to format it. Any time you need any sort of content formatted the way that WordPress normally does with something in the editor, yo need to use the the_content filter, like this:

<div class="tab-pane" id="3">
    <?php
        $meta_value = get_post_meta ($post->ID, '_post_note', true);
        // $meta_value = str_replace ( ']]>', ']]>', $meta_value ); // I don't know what this line is meant to do...

        echo apply_filters ('the_content', $meta_value);
    ?>
</div>



Source link