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

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.

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