Support

Account

Home Forums Gutenberg Adding Block Styles to an ACF Custom Block

Unread

Adding Block Styles to an ACF Custom Block

  • Hi,

    I’ve created a block using acf_register_block_type within a custom plugin using the init hook to run my function creating blocks. The goal is to replace the Spacer block with a series of set options for spacing to give a uniform appearance through the site.

    acf_register_block_type(array(
    ‘name’ => ‘spacer’,
    ‘title’ => __(‘Spacer’),
    ‘description’ => __(‘A block displaying a blank space.’),
    ‘category’ => ‘layout’,
    ‘icon’ => ‘editor-expand’,
    ‘keywords’ => array( ‘spacer’ ),
    ‘render_template’ => ‘template-parts/blocks/spacer/spacer.php’,
    ‘supports’ => array(
    ‘align’ => false
    )
    ));

    There doesn’t seem to be a way to add additional styles here.

    I’ve tried adding them using the wp.blocks.registerBlockStyle function within a js file. This is enqueued using the enqueue_block_editor_assets hook.

    wp.blocks.registerBlockStyle(‘layout/spacer’, {
    name:’standard’,
    label:’Standard’,
    isDefault:true
    });
    wp.blocks.registerBlockStyle(‘layout/spacer’, {
    name:’small’,
    label:’Small’
    });

    Unfortunately, the styles don’t show up when I select my new block in the CMS. I think the js file must be running before the new block has been registered.

    Has anyone encountered this situation before?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.