Connect Custom Fields to WordPress Blocks with the Block Bindings API
WordPress blocks make it possible to build page layouts from reusable pieces, while custom fields store content separately from those layouts.
Connecting the two with the Block Bindings API lets a block display field data directly, which can help site owners keep structured content consistent and easier to manage.
Understanding how the API links a custom field to a block is key to using that content reliably in the editor and on the front end.
This article explains how custom fields and block bindings work together in WordPress.
How the Block Bindings API Connects Fields
The Block Bindings API connects a block’s supported attributes to data from a source, such as a post’s custom field. You choose a source, identify the field, then map its value to an attribute the block can display. This is how bindings connect your content data to a block without copying the value into the page.
Set up the field data flow
- Add a custom field to a post and enter a value, such as a product subtitle.
- Register or select a binding source that can read that field.
- Configure the block’s binding to use the source and field name.
When you view the post, WordPress reads the field and supplies its value to the connected attribute. If the field changes, the displayed value can update too. Check that the field exists and contains the expected value. You’ll still edit the data where it’s stored.
Which WordPress Blocks Support Bindings?
Not every WordPress block supports bindings, so check whether the core block you want to use is included.
Then confirm which attributes, such as text or image fields, can receive your custom field values.
Core Block Support
While the Block Bindings API works with several core blocks, support depends on the block and the binding source you want to use. For a practical start, check these commonly supported blocks:
- Paragraph and heading: Use them when you want dynamic text, such as a short description or page heading, to appear in your layout.
- Image: Bind an image source when your content needs a dynamic image, and confirm the selected source supports that block.
- Button: Use a binding to supply button text or a link when your setup supports the connection.
You’ll find bindings useful in the site editor, but don’t assume every core block works with every source. Check the current WordPress documentation for the exact combinations available in your version.
Test a binding on a draft page first, then review the result in the editor and on the front end. This check helps protect your editor workflow and block theme compatibility.
Supported Block Attributes
A block can support bindings without letting you change every part of it, so check which attributes WordPress allows a source to fill.
Check supported attributes
Core binding support covers specific attributes in selected blocks, not every setting in the editor. For example, you can bind a Paragraph block’s content or a Heading block’s content.
An Image block supports bindings for its URL and alt text. The exact options depend on the block and the WordPress version you’re using.
Before you build a template, confirm attribute compatibility in the block’s documentation or by testing a binding in the editor. A block may appear in the bindings interface, yet still offer only certain attributes.
If your target attribute isn’t available, choose a supported attribute, use another block, or add custom code that registers the needed support. Test the result on the front end, too.
Register a Custom Field for Bindings
First, register your custom meta field with the correct type and settings so WordPress can use it.
Then use the built-in core/post-meta binding source to connect the registered field to a supported block attribute.
Register the Meta Field
To make a custom field available to block bindings, register it as post meta and enable REST API access. Add the registration to your theme or plugin, then confirm the field appears in the REST API response for the post type that uses it.
- Choose a key. Use a clear, lowercase meta key, such as
reading_time. Keep it consistent wherever you access the value. - Define field settings. Call
register_post_meta()with the post type, key, and an argument array. Settypeto the value’s data type, such asstring, and setsingletotruefor a single value. - Enable access. Set
show_in_resttotrue, and include asanitize_callbacksuited to the data. You may also set anauth_callbackto control who can edit it.
Register meta during init, and test the field in the editor and REST API.
Define the Binding Source
Registering the meta field makes it available through the REST API. WordPress provides the core/post-meta binding source for registered post metadata; a custom source is only needed for a different data source or custom retrieval logic.
Register a binding source
For an ordinary registered post meta field, use core/post-meta without registering another source. If you need a custom source, register it in a plugin with register_block_bindings_source() during init.
For a custom source, give it a clear name, such as my-plugin/product-meta, and define the callback that returns a value for the requested block attribute.
Map the field
In the callback, read the block’s binding arguments, then use Field Metadata Mapping to identify the meta key. For example, map a field argument to product_subtitle, and retrieve that value from the current post with get_post_meta().
Check that the post exists and the user can access the data before returning it. Return a safe, plain value, or an empty string when the field isn’t available. This keeps block output predictable.
Create Your First Custom Field Binding
With the custom field in place, connect it to a supported block using the built-in core/post-meta source and the registered field key.
Create Your First Binding
Add a binding definition to a block’s attributes. Set source to your registered source name, then provide the field key in args. For example:
'metadata' => [
'bindings' => [
'content' => [
'source' => 'core/post-meta',
'args' => [ 'key' => 'reading_time' ],
],
],
],This PHP array fragment describes a content binding for the registered reading_time field. It is not a complete block by itself: add the equivalent metadata to a Paragraph or Heading block in the Code Editor, as shown in the WordPress developer guide.
- Choose a target: Use
contentfor a paragraph or heading’s text. - Map Field to Block: Pass the exact registered field key in
args. - Check the result: Confirm your source returns a string and handles missing values safely.
Keep this setup focused; editor controls come later.
Bind Custom Fields in the Editor
In WordPress 6.5 and 6.6, add binding metadata to a supported block using the Code Editor. The visual custom-field binding interface is planned for WordPress 6.7; see the 6.7 developer note.
Set the source to core/post-meta and the key argument to the registered field name, then preview the block and the front-end page.
Make sure the field exists and contains a value for the current post. If the value doesn’t appear, confirm that your source supports the block and attribute you selected.
Preview Bound Content on the front end too, since your theme’s styles and the saved post can affect the final display.
Choose Code or Editor-Based Bindings
Use the Code Editor to add binding metadata in WordPress 6.5 or 6.6. A visual interface is planned for WordPress 6.7, while custom PHP sources provide more control over how values are retrieved.
Your choice depends on who manages the content and how much setup you need.
Use the Code Editor for existing versions, and watch for visual field selection in the upcoming WordPress 6.7 release.
- Use the Code Editor to add metadata for a supported core block and registered post meta field.
- Choose Code Bindings when you need to register a source, define how values are retrieved, or apply bindings consistently across templates. You’ll need to add and maintain PHP code.
- Plan for the visual binding controls announced for WordPress 6.7, and test them once that release is available.
Start with the built-in source; add a custom source only when you need its flexibility.
Fix Missing or Empty Field Values
If a block shows a blank value, first check that the custom field exists and contains data for the current post. Confirm you’ve entered the value on the post or page you’re previewing, not just on another item.
Diagnose the binding
To diagnose empty field values, check that the block uses the correct source and field name. A typo, wrong source, or unsupported block attribute can leave the block blank.
If you added a binding in code, review its attribute key and metadata registration.
Check the field value
Try validating field data types before changing the binding. A text attribute needs a compatible value, while a number or URL may not display as expected if the field stores a different type.
Check that the value isn’t empty, and confirm any format or sanitization code doesn’t remove it.
Finally, save your changes, refresh the editor, and preview the same post again. If the value still doesn’t appear, test with a simple text field to narrow down the cause.
Make Bound Content Accessible and Maintainable
Make bound content accessible by using clear text, meaningful link labels, and image alt text that describes the image’s purpose.
When you connect custom fields to blocks, check how each value works for visitors who use screen readers or keyboard navigation.
- Choose useful field values. Store complete labels, not vague text such as “Click here.” For images, write alt text that explains their purpose, or leave it empty when the image adds no information.
- Check the rendered page. Preview bound content on desktop and mobile, then test links with a keyboard and confirm headings follow a sensible order.
- Keep bindings maintainable. Use consistent field names, document each binding, and confirm fallback text appears when a value is missing.
These habits help you provide accessible content while making maintainable bindings easier to review and update.
Recheck them whenever you change fields or templates.
Frequently Asked Questions
Which WordPress Versions Support the Block Bindings API?
WordPress version compatibility begins at 6.5: that’s when Block Bindings availability arrived, just as many site owners needed it. You can use the API in WordPress 6.5 and later; earlier versions don’t support it natively.
Can Custom Field Bindings Be Used With Third-Party Plugins?
Yes, you can use custom field bindings with third-party plugins when their blocks support the Block Bindings API. Check each plugin’s documentation for Third Party Block Compatibility and Plugin Binding Support before connecting fields.
Do Bound Custom Fields Affect Page Performance?
Usually, bound custom fields won’t slow your pages noticeably. Think of them as one extra ingredient in a recipe: database queries add modest work, while page caching serves prepared results and keeps things speedy.
Can Visitors Edit Bound Custom Field Values?
No, visitors can’t edit bound custom field values by default. You control editing through your site’s forms or custom code. Set Visitor Edit Controls carefully, and review Custom Field Permissions to prevent unauthorized changes.
How Can You Migrate Bindings Between WordPress Sites?
You can migrate block bindings by exporting your source site’s content, templates, and custom field definitions, then importing them into your destination site. Export custom metadata too; recreate registered bindings and verify field names and values afterward.
- Block Bindings API
- Custom Fields
- WordPress blocks
About the author
Vladimir Mrkela
Senior WordPress Developer
I’m a senior WordPress developer and co-founder of Pixel Industry. I’ve spent more than 12 years building websites, custom plugins, and integrations for all kinds of projects. I enjoy working on complex architecture, solving tricky problems, and sharing what I learn along the way.