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

3b. Use the inline_style parameter

  • Best for: Plugin developers and theme developers
  • Where you would typically use it: In the main plugin PHP file or functions.php
  • Version requirements: WordPress 5 or higher

The value for the inline_style parameter is a combination of the CSS selector and the CSS properties.

function my_double_frame_styles() {
   register_block_style(
       'core/image',
       array(
           'name'         => 'double-frame',
           'label'        => __( 'Double-Frame', 'pauli' ),
           'inline_style' => '.wp-block-image.is-style-double-frame
                               img { border: 10px ridge lightgreen; }'
       )
   );
}
add_action( 'init', 'my_double_frame_styles' );
<img data-attachment-id="79432" data-permalink="https://wordpress.com/blog/2025/05/07/custom-block-styles/screenshot-80/" data-orig-file="https://en-blog.files.wordpress.com/2025/05/green-border-double-frame.jpg" data-orig-size="1032,509" data-comments-opened="1" data-image-meta="{"aperture":"0","credit":"","camera":"","caption":"Screenshot","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"Screenshot","orientation":"1"}" data-image-title="Screenshot" data-image-description data-image-caption="Screenshot

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