Home Forums Gutenberg extraProps on acf blocks


extraProps on acf blocks

  • Hi there,

    I am using acf pro to create some blocks which is working great so far.
    Now however I stumbled upon some issue which I havn’t found a solution for yet and could use some help.

    I created a custom plugin to extend some of the gutenberg core blocks behavior which is working fine:

    function addTWClasses(extraProps, blockType, attributes) {
    	extraProps.className = extraProps.className + ' my-custom-class';
    	return extraProps;

    this works well for all core blocks but not for any block created with acf_register_block_type using php.

    I am wondering why the classes do not get applied that way? Also if I output extraProps.className it say’s “acf-my-custom-block” but in frontend it does not.

    In php $block[‘className’] is null unless I add a class to the extra css classes field.

    Any help on this is much appreciated.

    Thank you.

  • I just noticed this on the register_block_type() page:

    acf_register_block_type( $settings );


    (array) (Required) Array of arguments for registering a block type. Any argument from the JavaScript registerBlockType() function may also be used.

    So if you normally add your props in registerBlockType(), you should be able to add them when you register the ACF block.

    However, as a person with very limited JS experience, I just add any additional classes in the block template code.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.