Render wp_editor input in theme file using get_post_meta

I have a meta box with wp_editor other than the main content editor.

    public function add_custom_meta_boxes() {
        add_meta_box(
            'ux_page_header',
            __( 'Page Header', 'ux' ),
            array($this, 'ux_render_page_header'),
            'page',
            'normal',
            'core'
        );
    }

    public function ux_render_page_header() {
        $page_header =  get_post_meta($_GET['post'], 'page_header' , true ) ;
        wp_editor( 
            htmlspecialchars_decode($page_header), 
            'ux_page_header', 
            $settings = array('textarea_name'=>'page_header') 
        );
    }

    public function ux_save_post_data($post_id) {

        if( !empty($_POST['page_header']) ) {
            $data = htmlspecialchars($_POST['page_header']);
            update_post_meta($post_id, 'page_header', $data );
        }
    }

But when I am retrieving this data, it just prints the html code. How to render this html?

$header = get_post_meta( get_the_ID(), 'page_header', true ); 
echo $header;

Related posts

1 comment

  1. When you save the info here: $data = htmlspecialchars($_POST['page_header']); the data is encoded using htmlspecialchars so to render the content as HTML when calling get_post_meta, you will need to decode it:

    $header = htmlspecialchars_decode(get_post_meta( get_the_ID(), 'page_header', true ));
    echo $header;
    

Comments are closed.