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;
}
wp.hooks.addFilter(
'blocks.getSaveContent.extraProps',
'blob/add-tw-classes',
addTWClasses
);
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.
p13
I just noticed this on the register_block_type()
page:
acf_register_block_type( $settings );
$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.