Support » Fixing WordPress » Text in custom wordpress metabox behaves strangely after saving

  • Ok, so Ive create a couple custom meta boxes for a custom post type and they function perfectly fine as expected, however something I cant figure out is why once I save some data into one of the custom meta fields – when I return to the post and view it again the text appears jumbled and not aligned to the left…its the oddest thing. A google searched didn’t render any results on this so I figured Id take a stab at the forums, hope you guys can help.

    Heres what my markup looks like in my functions.php –

    // Register Custom Post Type Meta Boxes -- Description Field
    add_action( 'add_meta_boxes', 'store_description_meta_box_add' );
    function store_description_meta_box_add()
    	add_meta_box( 'epr_store_description_meta_id', 'Product Description', 'store_description_meta_box_cb', 'epr_store', 'normal', 'high' );
    function store_description_meta_box_cb( $post )
    	$values = get_post_custom( $post->ID );
    	$textbox = isset( $values['meta_box_description_text'] ) ? esc_attr( $values['meta_box_description_text'][0] ) : '';
    	wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
    		<textarea name="meta_box_description_text" id="meta_box_description_text" style="width:98%; height:100px;text-align:left;">
    			<?php echo $textbox; ?>
    add_action( 'save_post', 'epr_description_meta_box_save' );
    function epr_description_meta_box_save( $post_id )
    	if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    	if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
    	if( !current_user_can( 'edit_post' ) ) return;
    	$allowed = array(
    		'a' => array(
    			'href' => array()
    	if( isset( $_POST['meta_box_description_text'] ) )
    		update_post_meta( $post_id, 'meta_box_description_text', wp_kses( $_POST['meta_box_description_text'], $allowed ) );

    You’ll notice I even tried placing inline styles inside the textarea tag in hopes that it would remedy the problem however it didnt help even though firebug show that the styles are being used.

    A screenshot of how the text appears after saving (note how it appears indented almost):

  • The topic ‘Text in custom wordpress metabox behaves strangely after saving’ is closed to new replies.