ASHISH KANAJARIYA0%Preparing your experience
Skip to content

WordPress Block Bindings API: Connect Blocks to Custom Fields Without Custom Blocks

Laptop screen showing code, illustrating the WordPress Block Bindings API

For years, showing a custom field inside a block theme meant one of two things: writing a custom block or adding a shortcode. Both work, but both add code to maintain for something that should be simple. The WordPress Block Bindings API changes that. It lets a normal Paragraph, Heading, Image or Button block take its content from a data source such as post meta, without building anything new.

The API arrived in WordPress 6.5 and has grown with almost every release since. WordPress 6.9 added new core sources and a filter for supported attributes, and WordPress 7.0 opened Pattern Overrides to custom blocks. In this guide I explain how block bindings work, which blocks support them, how to register your own source, and how I use them on real projects.

What Is the WordPress Block Bindings API?

A block binding is a connection between one attribute of a block and an external value. Instead of storing the text of a paragraph inside the post content, the paragraph says, in effect, my content comes from this source, with these arguments. When WordPress renders the page, it asks the source for the value and places it in the block.

The connection is stored in the block’s metadata attribute under a bindings key. Each binding names a source and optional args. Here is a paragraph bound to a custom field called book_author:

<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"book_author"}}}}} -->
<p></p>
<!-- /wp:paragraph -->

The paragraph’s content attribute is bound to the core/post-meta source, and the key argument tells the source which field to read. On a book post, the paragraph shows the author’s name. On another book post, it shows that post’s author. The template stays the same while the data changes.

Why this matters

  • Less custom code. Many layouts that once needed a bespoke block can now use core blocks with bindings.
  • Full design control. Bound blocks keep every typography, colour and spacing option that core blocks offer, so designers can style dynamic data in the Site Editor.
  • Cleaner templates. A single template for a custom post type can display structured data for every entry.
  • Future-friendly content. Data lives in fields rather than being typed into layouts, which makes redesigns and migrations easier.

Which Blocks and Attributes Support Bindings?

Not every attribute can be bound. According to the Block Bindings reference in the Block Editor Handbook, these core blocks support bindings by default:

BlockBindable attributes
Paragraphcontent
Headingcontent
Imageid, url, title, alt, caption
Buttonurl, text, linkTarget, rel
Navigation Linkurl
Navigation Submenuurl
Post Datedatetime

That covers a surprising range of real needs: a product’s subtitle, an event’s booking link, a team member’s photo and job title, or a property’s price. Since WordPress 6.9, developers can extend this list with the block_bindings_supported_attributes filter, which I cover later.

The Core Binding Sources

WordPress ships with several sources out of the box. Each one answers a different question.

core/post-meta

This is the source most people start with. It reads a custom field from the current post. Two rules apply: the field must be registered with show_in_rest set to true, and its key cannot start with an underscore, because underscore-prefixed meta is treated as protected.

core/post-data and core/term-data

Added in WordPress 6.9, core/post-data exposes the post’s date, modified date and link through a field argument. core/term-data exposes term fields such as name, link, slug, description and count, using the term ID and taxonomy provided by block context, for example inside a term template.

core/pattern-overrides

This source powers Pattern Overrides, which let each copy of a synced pattern change specific content while the design stays in sync. It deserves its own section below.

Step by Step: Binding a Block to a Custom Field

Let’s build a small example. Imagine a site that reviews books, where each post stores the book’s author in a custom field.

Step 1: Register the field

Add this to a small plugin or your theme’s functions.php. Registering the field tells WordPress its type and makes it available to the REST API and the editor:

add_action( 'init', function () {
    register_post_meta( 'post', 'book_author', array(
        'show_in_rest' => true,
        'single'       => true,
        'type'         => 'string',
        'default'      => '',
    ) );
} );

Step 2: Connect a block

Open a single post template in the Site Editor, or a post in the block editor, and add a Paragraph block. In recent WordPress versions, the block settings sidebar shows an Attributes panel where administrators can connect a supported attribute to an available field. You can also switch to the Code editor and add the metadata.bindings attribute shown at the start of this article.

Step 3: Edit the value

When the source allows it, editors can change a bound value directly in the block, and the new value is saved back to the custom field rather than to the post content. This is one of my favourite parts of the API: clients edit text where they see it, while the data stays structured behind the scenes.

Developer writing code on a laptop at a desk

Registering Your Own Binding Source

Post meta covers many cases, but sometimes the data lives elsewhere: a site option, a value from an external service, or a calculation. For these, you can register a custom source with register_block_bindings_source(). It must be called on the init hook and takes a unique name plus an arguments array.

add_action( 'init', function () {
    register_block_bindings_source( 'ak/site-info', array(
        'label'              => __( 'Site info', 'ak' ),
        'get_value_callback' => function ( array $source_args ) {
            $field = isset( $source_args['field'] ) ? $source_args['field'] : '';

            if ( 'tagline' === $field ) {
                return get_bloginfo( 'description' );
            }

            if ( 'year' === $field ) {
                return wp_date( 'Y' );
            }

            return null;
        },
    ) );
} );

A Paragraph bound to ak/site-info with the argument {"field":"year"} now always shows the current year, which is handy for a copyright line in the footer. The callback receives three parameters: the source arguments, the block instance and the attribute name. Many sources only need the first, but the block instance is useful when a value depends on block context, such as the current post ID inside a Query Loop.

Two optional extras are worth knowing:

  • uses_context lists the block context keys your callback needs, for example postId and postType.
  • The block_bindings_source_value filter, available since WordPress 6.7, lets you adjust any source’s value before it reaches the block. It is useful for formatting, such as adding a currency symbol to a price.

Making a custom source editable in the editor

The PHP registration handles front-end rendering. For a richer editing experience, WordPress 6.7 added JavaScript registration with registerBlockBindingsSource(). It accepts getValues to show values in the editor, setValues to save changes, and canUserEditValue to decide whether editing is allowed. Since WordPress 6.9, a getFieldsList function can also provide the fields that appear in the Attributes panel dropdown, so editors can choose from your fields without touching code.

Extending Supported Attributes in WordPress 6.9 and Later

The default list of bindable attributes is a sensible starting point, but custom blocks often have their own attributes worth binding. WordPress 6.9 introduced the block_bindings_supported_attributes filter, plus a per-block variant named block_bindings_supported_attributes_{$block_type}. Here is how a custom testimonial block could make its quote and author attributes bindable:

add_filter(
    'block_bindings_supported_attributes_ak/testimonial',
    function ( $attributes ) {
        $attributes[] = 'quote';
        $attributes[] = 'author';
        return $attributes;
    }
);

For dynamic blocks, bound values are passed to the block’s render callback, so your PHP template receives the resolved data automatically. For static blocks, WordPress uses the HTML API to find attributes sourced from html, rich-text or attribute selectors and replaces their values. If you are curious about how far the HTML API has come, my article on wp_kses() and the HTML API explains the bigger picture.

Pattern Overrides in WordPress 7.0

Synced patterns are perfect for repeated sections such as call-to-action boxes, testimonials or pricing cards. Change the design once and every copy updates. The challenge has always been content: you want the same design, but a different headline or button link on each page.

Pattern Overrides solve this. Inside a synced pattern, you select a block, open the Advanced panel and enable overrides, giving the block a name. Each copy of the pattern can then change that block’s content while the layout remains synced. Under the hood, the override is stored through the core/pattern-overrides binding source, keyed by the block’s name.

Originally, overrides only worked with a fixed set of core blocks. As described in the WordPress 7.0 developer note on Pattern Overrides, any block attribute that supports block bindings now also supports Pattern Overrides. That means the same filter you use to make a custom block bindable also makes it overridable. One configuration unlocks both features.

Practical Use Cases

Here are patterns I have found genuinely useful with the Block Bindings API:

  • Team directories. A Team Member post type with fields for role, photo and LinkedIn URL, displayed through Heading, Image and Button blocks in a single template.
  • Events. Date, venue and booking link bound to blocks, so organisers only fill in fields and the design stays consistent.
  • Real estate and listings. Price, location and gallery image pulled from fields, with styles controlled in the Site Editor.
  • Global details. Phone numbers, opening hours or the current year from a custom source, updated in one place and shown everywhere.
  • Landing page sections. Synced call-to-action patterns with overridable headlines and links, so marketing teams can reuse a polished design on every campaign page.

If you are interested in other modern block-editor features, my guides to the WordPress Interactivity API and responsive styling without CSS pair nicely with block bindings. Together they let you build dynamic, interactive and responsive layouts with very little custom code.

Best Practices

  1. Register every field. Use register_post_meta() with a type and default value. Registered fields are validated, appear in the REST API and work with the editor interface.
  2. Use namespaced source names. Prefix custom sources with your plugin or theme slug, such as ak/site-info, to avoid collisions.
  3. Escape output appropriately. Return plain values from your callback and let core handle the block markup. If a value contains HTML, sanitise it before storage.
  4. Return null when there is no value. This lets the block fall back gracefully instead of printing empty or misleading text.
  5. Keep sources fast. Callbacks run during rendering. Cache expensive lookups, especially calls to external services, so pages stay quick. A persistent object cache, which I explain in my Redis object cache guide, makes this easy.
  6. Test in a sandbox first. Bindings change how templates render, so try them in a local or browser-based environment before going live. My guide to WordPress Playground and Studio shows how to spin one up in seconds.

Block Bindings vs Custom Blocks vs Shortcodes

Each approach still has its place. Block bindings are ideal when an existing core block already has the right markup and you only need to change where its data comes from. Custom blocks remain the best choice for unique interfaces with their own controls, such as a booking widget or an interactive calculator. Shortcodes are useful for compatibility with older content and classic themes. In my projects, bindings now replace most of the small, display-only custom blocks I used to write, which means less code to maintain and a more consistent editing experience for clients.

Frequently Asked Questions

Do I need a plugin to use block bindings?

No. The API is part of WordPress core from version 6.5. Custom field plugins can make field management easier, and many of them now integrate with block bindings, but they are optional.

Can I bind protected meta that starts with an underscore?

Not with the core post meta source. Underscore-prefixed keys are treated as protected. If you need to display one, register a custom source that reads and returns the value safely.

Do bindings work with classic themes?

Yes, inside block content. Bindings are part of how blocks render, so they work wherever blocks are used, including post content in classic themes. They shine most in block themes, where templates are built with blocks.

Conclusion

The WordPress Block Bindings API turns core blocks into flexible, data-driven building blocks. With post meta, post and term data, custom sources and Pattern Overrides, you can build structured templates that stay easy for clients to edit. Start with a single registered custom field and a bound Paragraph block, then expand to custom sources and overridable patterns as your project grows. It is one of the most practical additions to modern WordPress development, and it keeps getting better with each release. For the original introduction, the Block Bindings API announcement on Make WordPress Core is well worth reading.

Images: photos by Arnold Francisca and Danial Igdery on Unsplash.

Leave a Reply

Your email address will not be published. Required fields are marked *