This tutorial shows you the most basic way to use a custom field with a paragraph block. There’s only simple steps :
- Add PHP code to your child themes functions file or code snippets plugin to register your post meta key. In his case we use wpsites_text for the name of our custom field key.
- Create a new custom field key and add a value you want to display in a paragraph.
- Add the custom field content from the block attribute settings to your editor
1. PHP : Register Post Meta Key
Here’s the PHP code that registers your post meta key for use in a paragraph block :
add_action( 'init', 'wpsites_register_post_meta_key' );
function wpsites_register_post_meta_key() {
register_meta(
'post',
'wpsites_text',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'sanitize_callback' => 'wp_strip_all_tags'
) );
}
2. Create New Custom Field
Now all you need to do is add a new custom field named wpsites_text and add the value you want to output on the frontend.

3. Insert Custom Field for Block Attribute
In the paragraph blocks settings, scroll down to Attributes, click Attributes > Content > Content to insert the value of your custom field into any paragraph block.

You’ve now made your first block binding enabling the use of custom fields in the paragraph block.
Tested using the Genesis Sample child theme by StudioPress and the TT4 default block theme for WordPress.






Leave a Reply