Skip to content
Web with Wordpress Logo
  • Home
  • Blogs
  • Pricing
  • About Us
  • Contact Us
Get a quote
Home / WordPress Development
WordPress Development

Custom Fields in the Block Editor: register_post_meta and Sidebar Panels

YuviNovember 14, 20267 min read
Custom Fields in the Block Editor: register_post_meta and Sidebar Panels

Custom fields have always been one of WordPress’s most useful features. A post has a title and content, but real projects need more: an event’s date and venue, a product’s specification, a case study’s client name and results. For years, developers added these with meta boxes, PHP-rendered forms below the editor. The function at the heart of the modern approach is register_post_meta.

Meta boxes still work in the block editor, through a compatibility layer. But they feel out of place, appear in a cramped area below the content, and they save through a separate request after the main post saves. That can cause odd behaviour, especially with autosaves and revisions, and some editor features don’t work when meta boxes are present.

The modern approach is to register post meta so the block editor understands it, then add a small panel to the editor’s sidebar. It takes a little JavaScript, but the result is a native experience: fields that save with the post, work with undo and integrate with block bindings and the REST API.

Step 1: Register the meta

Everything starts with register_post_meta. This tells WordPress the meta key exists, what type it is, how to sanitise it and that it should be available through the REST API, which the block editor uses.

The important parts:

  • type and single describe the data. Single means one value per post, rather than multiple rows with the same key.
  • show_in_rest exposes it to the REST API and the block editor. The schema adds validation: the API rejects values outside the enum.
  • sanitize_callback cleans values before saving.
  • auth_callback controls who can edit the field.
  • default provides a value when nothing has been saved.

Note that the post type must support custom fields for the meta to appear in the REST API. Core posts and pages do. For custom post types, include ‘custom-fields’ in the supports array.

Protected meta keys

Meta keys starting with an underscore are considered protected and are hidden from the core Custom Fields panel. That’s often desirable, but protected keys require an auth_callback that returns true for users who should edit them, otherwise the REST API refuses updates.

Step 2: Check it in the REST API

Before writing any JavaScript, confirm the meta appears. Fetch a post through the API while logged in, or use the browser console in the editor:

You should see acme_reading_level with its default value. If not, check show_in_rest and custom-fields support.

Step 3: Build a sidebar panel

The block editor’s sidebar has a “Post” tab with panels for status, categories, featured image and so on. You can add your own panel there with the PluginDocumentSettingPanel component.

Create a JavaScript file, built with @wordpress/scripts:

When the editor changes the value, editPost updates the post’s edited state, exactly like changing the title. The value saves when the post saves, with no separate request, and undo works.

In older WordPress versions, PluginDocumentSettingPanel lived in @wordpress/edit-post. Since WordPress 6.6, it’s exported from @wordpress/editor, which also makes it available in the site editor.

Step 4: Enqueue the script

Load the script only in the block editor:

The asset file, generated by @wordpress/scripts, lists the WordPress script dependencies automatically.

Using the useEntityProp shortcut

For simpler code, the core-data package provides useEntityProp, which reads and writes a property of the current post in one line:

It’s convenient inside blocks as well as panels, so a block can display or edit post meta directly.

Other field types

The same pattern works for any field type. Some common components:

  • TextControl for single-line text
  • TextareaControl for longer text
  • ToggleControl for booleans
  • DatePicker or DateTimePicker for dates
  • MediaUpload with a button for images, storing the attachment ID as an integer

For complex data, register the meta with type object or array and a full JSON schema. The REST API validates the structure, which protects against malformed data.

Displaying meta on the front end

With meta registered properly, you have several options for display:

  • In templates, using get_post_meta as always.
  • With block bindings, connecting a core Paragraph or Heading block to a meta value so editors place it visually. That’s covered in detail in our article on block bindings.
  • In a custom dynamic block that reads the meta and renders it.

Remember to escape on output, regardless of sanitising on input.

What about ACF and similar plugins?

Advanced Custom Fields, Meta Box, Pods and similar tools remain excellent choices, especially for complex field groups, repeaters and non-developers building fields through an interface. They handle registration, the interface and storage for you, and modern versions integrate with the block editor and block bindings.

The approach in this article suits developers who want a lightweight, dependency-free solution for a handful of fields, or who are building a plugin for distribution where depending on a third-party field plugin isn’t appropriate.

Common issues

The field doesn’t save. Usually the meta isn’t registered with show_in_rest, the post type lacks custom-fields support, or the auth_callback returns false.

The value saves but is empty. The sanitize callback might be stripping it, or the schema type doesn’t match the value being sent.

Old meta box and new panel both exist. Remove the old meta box, or editors will see two fields fighting over the same value.

Revisions don’t include meta. Since WordPress 6.4, you can add ‘revisions_enabled’ => true when registering meta, so meta changes are stored with revisions.

Choosing the right place in the interface

The document settings panel isn’t the only place to put custom fields. The block editor offers several slots, and choosing well makes fields easier to find.

PluginDocumentSettingPanel adds a collapsible panel to the Post tab in the sidebar. It’s the right place for page-level settings that editors change occasionally, like reading level, event details or SEO options.

PluginSidebar adds a whole new sidebar with its own icon in the toolbar. It suits plugins with many settings or a richer interface, such as an SEO plugin’s analysis panel.

PluginPrePublishPanel adds content to the checklist shown before publishing. It’s ideal for reminders and required fields, such as “Choose a reading level before publishing”.

PluginPostStatusInfo adds a row to the summary area near the status and visibility settings, which suits small, important values.

Inside a block, using useEntityProp, is the right choice when the value belongs visually in the content, such as an event date displayed as part of the layout.

Match the location to how often the field is used and how important it is. Fields editors must fill in for every post deserve a prominent place. Fields used rarely can live in a collapsed panel.

Validation and required fields

Sometimes a field must be filled before publishing. The block editor lets you lock saving or publishing until a condition is met:

Use this sparingly and explain why the post can’t be saved, for example with a notice in the panel. Locking saving without explanation confuses editors and can lead to lost work. Locking only publishing, while still allowing drafts to save, is usually kinder.

Remember that the editor is not the only way posts are created. Imports, the REST API and WP-CLI bypass the JavaScript checks entirely. If a value truly must exist, enforce it on the server too, for example with a default or by checking in a save_post hook.

Performance considerations

Registered meta is loaded with the post in the REST API response, and get_post_meta uses WordPress’s object cache, so reading meta is generally fast. Problems appear when meta is used for querying. Filtering or sorting large numbers of posts by meta values is slow, because the postmeta table isn’t designed for that kind of query.

If you need to filter content by a field, such as showing only advanced articles, a taxonomy is often a better fit than meta. Taxonomies are indexed for exactly that purpose and give you archive pages for free. A reading level, for instance, could reasonably be a custom taxonomy instead of a meta field. Choose based on how the data will be used: meta for values that describe a single post, taxonomies for values used to group and filter many posts.

Frequently asked questions

Do classic meta boxes still work in the block editor?

Yes, through a compatibility layer. They’re fine for legacy projects, but new work should use registered meta and sidebar panels.

Can I show the panel only for certain post types?

Yes. Check the current post type in the component, as in the example, and return null for others. Register the meta only for the relevant post types too.

Is meta registered this way available in the REST API publicly?

Meta exposed with show_in_rest appears in REST responses for that post. For published posts, that’s public. Don’t expose sensitive data this way.

Can blocks write to post meta?

Yes, with useEntityProp. It’s how some blocks store page-level data. Be careful that the same meta isn’t edited by several blocks at once.

block editorcustom fieldsplugin sidebarpost metarest api

Post navigation

PreviousWordPress Coding Standards and PHPCS: Cleaner, Safer Code With Less Effort
NextDelivering Updates for Private and Client Plugins Outside WordPress.org

Keep reading

WordPress Development

WordPress Playground: Instant Test Sites, Demos and Bug Reports in the Browser

November 15, 2026
WordPress Development

Curating the Block Editor for Clients: Fewer Options, Fewer Mistakes

November 15, 2026
WordPress Development

Plugin Upgrade Routines: Changing Your Database Safely Between Versions

November 15, 2026
Web with Wordpress Logo

We build, fix and grow WordPress websites, from first launch to ongoing care.

Quick links

  • Home
  • Blog
  • About Us
  • Contact Us

Topics

  • WordPress Development
  • SEO
  • WooCommerce
  • WordPress Security
  • Performance
  • Web Strategy

Contact

  • Haryana, India

© 2026 Web With WordPress. All rights reserved.

  • Privacy Policy