Unlock Hidden Power: 6 Little-Known Ways to Master Custom Block Styles in WordPress
Here is some example code using this method to add a purple border style.
function my_purple_border_styles() {
wp_enqueue_style(
'my-image-block-style',
plugin_dir_url(__FILE__) . '/my-purple-border.css',
array( 'wp-edit-blocks' ),
'1.0'
);
register_block_style(
'core/image',
array(
'name' => 'purple-border',
'label' => __( 'Purple Border, slightly rounded', 'pauli' ),
'style_handle' => 'my-image-block-style'
)
);
}
And here is the accompanying my-purple-border.css
file, which is placed into the plugin’s root folder.