Skip to content

Instantly share code, notes, and snippets.

Last active December 19, 2022 08:51
What would you like to do?
Register WordPress block styles with PHP

Register block styles with PHP

You can now register different styles for WordPress blocks using PHP - no Javascript needed! Use the code here, either in your themes functions.php file or a plugin.

The name paramter forms part of the CSS class that is added to the block. Don't forget, this is all that block styles do, they had an additional class which then allows you to style them in a different way.

The class will take the form of is-style-{NAME}. So in the example here, when the "EyeBrow" style is applied to a heading, that heading block would have the class of is-style-eyebrow.

* Register some default block editor styles for this block.
function hd_testimonials_register_testimonials_block_styles() {
// add the small image style.
'core/heading', // name of your block
'name' => 'eyebrow', // part of the class that gets added to the block.
'label' => __( 'Eyebrow Heading', 'hd-testimonials' ),
add_action( 'init', 'hd_testimonials_register_testimonials_block_styles' );
Copy link

How do i add attributes to this?

Copy link

wpmark commented Dec 19, 2022

@ryandayalo I am not entirely sure what you mean here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment