Unlock Hidden Power: 6 Little-Known Ways to Master Custom Block Styles in WordPress
This code example goes into the theme’s functions.php
file or your plugin’s *.php
file.
function pauli_block_editor_scripts() {
wp_enqueue_script(
'pauli-editor',
get_theme_file_uri( '/js/curate-core.js' ),
array( 'wp-blocks', 'wp-dom' ),
wp_get_theme()->get( 'Version' ), true
);
}
add_action( 'enqueue_block_editor_assets', 'pauli_block_editor_scripts' );
This code should go in the JavaScript file curate-core.js
:
wp.domReady( function() {
wp.blocks.registerBlockStyle(
'core/image', {
name: 'black-border',
label: 'Black Border',
}
);
} );
You can then add our block styles to your theme’s style.css
file using the automatically added class name, is-style-black-border
.