# Make a Custom Field Usable in Blocks

> Registers a custom field (such as a subtitle) with the REST API so it can be connected to Paragraph or Heading blocks through Block Bindings and edited right in the block.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: block-bindings, custom-fields, meta
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/custom-field-for-block-bindings/

## Code

```php
// Post type and custom field name.
$wpide_bound_post_type = 'post';
$wpide_bound_meta_key  = 'subtitle';

add_action( 'init', function () use ( $wpide_bound_post_type, $wpide_bound_meta_key ) {
    register_post_meta( $wpide_bound_post_type, $wpide_bound_meta_key, array(
        'type'              => 'string',
        'single'            => true,
        'show_in_rest'      => true,
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'label'             => ucfirst( str_replace( array( '-', '_' ), ' ', $wpide_bound_meta_key ) ),
        'auth_callback'     => function ( $allowed, $meta_key, $post_id ) {
            return current_user_can( 'edit_post', $post_id );
        },
    ) );
} );
```

## Notes

Requires WordPress 6.5 or newer. Bind it with {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"subtitle"}}}}}. Change the post type and field name at the top.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Make a Custom Field Usable in Blocks" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
