I've got my blocks registered properly and functioning.
My only gripe is that I don't want the blocks to be used more than once in the same post.
Is it possible to restrict block behavior like this? The documentation is horrible.
I've got my blocks registered properly and functioning.
My only gripe is that I don't want the blocks to be used more than once in the same post.
Is it possible to restrict block behavior like this? The documentation is horrible.
When registering your own blocks, you can set the multiple option of the supports property to false:
supports: {
// Use the block just once per post
multiple: false
}
Source: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#multiple.
For anyone who needs this too, here is how you restrict a block for single use only:
// A Sample Block
acf_register_block(array(
'name' => 'blockname',
'title' => __('Block Name','slug'),
'description' => __('A translatable description','slug'),
'render_callback' => 'theme_block_render',
'category' => 'embed', //the block category (optional)
'align' => 'wide', // default value for width
'mode' => 'auto', // default value for switching auomatically between edit and view mode
'supports' => array('align' => array('wide','full' ),'multiple' => false), // wide and full are optional, those are for setting the width. SET MULTIPLE TO FALSE HERE!
'icon' => 'welcome-view-site', // Use a dashicon, for example dashicons-welcome-view-site
'keywords' => array( 'blockname', 'image','text' ), //set some keywords for search
));
Further documentation can be found here: https://www.advancedcustomfields.com/resources/acf_register_block_type/
in block.json set "multiple" to false in "supports":
"category": "widgets",
"icon": "smiley",
"supports": {
"html": false,
"multiple": false
},
"attributes": {