Ask Your Question
2

How can all the block supports be activated for an ACF Block?

asked 2021-11-15 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-06 04:00:00 +0000

woof gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-15 11:00:00 +0000

Seen: 8 times

Last updated: Apr 06 '23