Unlock Hidden Power: 6 Little-Known Ways to Master Custom Block Styles in WordPress

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.

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

You May Have Missed