In the WordPress Gutenberg Editor, I am trying to programmatically set a default class on an image block, which is applied without the user manually adding it via the 'Additional CSS' field.
I have tried applying a default style on image blocks, which works initially -
wp.blocks.registerBlockStyle( 'core/image', {
name: 'retailResidential',
label: 'Retail & Residential',
isDefault: true
});
But I need to update this default class after a user changes a field on a custom dropdown. When this dropdown is changed, I am unregistering the block style, then registering a new default block style - but it has no effect for additionally created images (does not create an image with the updated default style, still uses the old).
wp.blocks.unregisterBlockStyle(
'core/image',
[ 'retailResidential', 'weddingsEvents', 'advertisingEditorial']
);
Does the editor need to be refreshed after updating the default image block style? or is there an alternative, better way of doing this?
reference for updating block styles
from Can I use Javascript to update a default class in the Wordpress Editor?
No comments:
Post a Comment