Gutenberg example for creating sidebar https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/plugin-sidebar-0/ does not keep what is entered in the box. After refreshing the page, entered content is gone end text box is empty. I guess it is some kind of REST problem?

I just checked, when updating post, meta field is sent via POST request, therefore it is not a REST problem:

{"meta":{"sidebar_plugin_meta_block_field":"Jozica1"},"content":" ... etc

PHP Code:

add_action( 'init', function () {
    if (is_admin()) {
        wp_register_script( 'gmk-sidebar-js', get_template_directory_uri() . '/js/sidebar-panel.js',
        [ 'wp-plugins', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data' ]
        wp_register_style( 'gmk-sidebar-style', get_template_directory_uri() . '/css/admin-guten-sidebar.css' );

        register_post_meta( '', 'sidebar_plugin_meta_block_field', array(
            'show_in_rest' => true,
            'single' => true,
            'type' => 'string',
        ) );
} );

1 Answer 1


Registration of meta field must happen outside of admin area check. I had it enclosed in if (is_admin) check, so it was only happening when it passed this test. This was incorrect.

The question is duplicate and original question and answer are here: Plugin Sidebar is not Saving Meta Attribute to Post/Page after "Update"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.