To activate all the block supports for an ACF Block, you can use the following code:
add_action('acf/init', 'my_acf_init');
function my_acf_init() {
if( function_exists('acf_register_block') ) {
// register a new block
acf_register_block(array(
'name' => 'my-custom-block',
'title' => __('My Custom Block'),
'description' => __('A custom block.'),
'render_template' => 'path/to/template.php',
'category' => 'formatting',
'icon' => 'admin-comments',
'keywords' => array( 'custom', 'block' ),
'supports' => array(
'align' => array( 'left', 'center', 'right', 'wide', 'full' ),
'anchor' => true,
'html' => false,
'multiple' => true,
'reusable' => true,
'mode' => true,
),
));
}
}
In this example, we are registering a new block called my-custom-block
. We are setting various properties including the block's supports
array, which specifies the features that are supported by the block.
The supports
array includes the following options:
align
: Allows the block to be aligned left, center, right, wide, or full.anchor
: Allows the block to be given an anchor ID for linking to.html
: Allows the block to include custom HTML.multiple
: Allows multiple instances of the block to be added to the same post.reusable
: Allows the block to be saved as a reusable block.mode
: Allows the block to be used in both the block editor and the classic editor.By including all of these options in our supports
array, we are activating all of the block supports for our custom block.
Asked: 2021-11-15 11:00:00 +0000
Seen: 9 times
Last updated: Apr 06 '23