Mastering Customized Block Kinds in WordPress: 6 Strategies for Theme and Plugin Builders

Mastering Customized Block Kinds in WordPress: 6 Strategies for Theme and Plugin Builders

Block Taste Permutations (block types) permit builders to give content material creators pre-made styling choices for core blocks, making sure logo consistency and streamlining content material manufacturing. The use of block types too can get rid of the wish to create customized blocks, lowering code upkeep.

On this information, you’ll be told a number of techniques so as to add customized block types in WordPress, whether or not you’re operating with a theme or a plugin. We’ll quilt choices the use of JSON (theme.json), PHP (register_block_style()), and JavaScript, with transparent steering on which manner fits which scenario.

You’ll additionally discover ways to take away core block types from the editor and curate the enjoy to your content material creators. 

The theme.json code refers to dam types as “permutations” (quick for “block genre permutations”), which is infrequently perplexed with block permutations or International Kinds permutations. This put up refers to those as “block types” to steer clear of confusion.

This put up begins with easy examples and regularly introduces extra complex strategies for including block types, from fast theme tweaks to plugin-based approaches.

The code referenced on this put up may be to be had on GitHub: 

You’ll need to have a fundamental working out of CSS to apply alongside. Being pleased with theme.json may be key, and figuring out just a little about PHP and WordPress hooks will surely come in useful.

To apply alongside or use the instance code, you’ll use Studio, our loose and open supply native building surroundings, to be had for Mac and Home windows.

  1. What are customized block types?
  2. Approach 1: upload a block genre by way of a JSON document (/types folder) 
  3. Approach 2: sign up block genre in PHP and magnificence it by way of theme.json
    1. Sign up block genre 
    2. Upload styling to theme.json
  4. Approach 3: upload a block genre with register_block_style() (PHP)
    1. 3a. Use the style_data parameter
    2. 3b. Use the inline_style parameter
    3. 3c. Use the style_handle parameter
  5. Approach 4: sign up block types the use of JavaScript + CSS
  6. Non-compulsory: casting off undesirable core block types
  7. Abstract: customized block types at a look
  8. Assets to be informed extra

What are customized block types?

Customized block types allow you to outline choice visible therapies for present blocks, like including a border, converting the background, or tweaking typography. 

When the block is chosen, those customized types will seem within the Kinds panel inside the editor sidebar, giving content material creators simple techniques to use constant, reusable design patterns. You’ll create as many customized block types as you’d like.

Beneath you’ll in finding an instance of the Symbol block. The Kinds panel under presentations 4 types: Default, Rounded, Red Border, and Purple Border (which is the chosen genre appearing within the editor).

A red border around an image in the WordPress editor

We’ll stroll thru six techniques so as to add customized block types in WordPress, from easy theme edits to extra complex strategies.

Approach 1: upload a block genre by way of a JSON document (/types folder) 

  • Absolute best for: Theme builders
  • The place you could possibly usually use it: Recurrently in issues 
  • Model necessities: WordPress 6.6 or upper with theme.json v3 

For theme builders, essentially the most streamlined manner so as to add customized block types to a theme is so as to add a brand new document to the /types folder. 

This technique calls for upgrading the theme.json schema to v3, which is simplest to be had in WordPress 6.6 and above. As a theme developer, you could possibly both require your customers to put in the Gutenberg plugin or replace the minimal requirement to your theme to WordPress 6.6 to verify the whole lot works as supposed.

Say we needed so as to add a blue border genre known as image-blue-border.json.

{
	"$schema": "https://schemas.wp.org/trunk/theme.json",
	"model": 3,
	"identify": "Blue Border",
	"slug": "blue-border",
	"blockTypes": [ "core/image" ],
	"types": {
            "border": {
                    "colour": "#00f9ff",
                    "genre": "forged",
                    "width": "4px",
                    "radius": "15px"
                },
			"shadow": "var(--wp--preset--shadow--natural)"
		}
}

With theme.json v3, the metadata knowledge for a block’s genre is mechanically registered inside the WP_Block_Styles_Registry:

  • The identify is equal to the label from the register_block_style code.
  • The slug is very similar to the title assets of the register_block_style serve as.
  • The blockTypes assets can be utilized to assign a method to a specific block or sequence of blocks.
a blue border around the image block in the WordPress editor

The code "shadow": "var(--wp--preset--shadow--natural)" refers back to the preset “Herbal” shadow genre in WordPress. Through the use of a preset variable, your block will mechanically mirror any international genre adjustments, retaining your design constant throughout issues and updates.

While you save your code adjustments:

  • Your new genre is added to the Kinds panel for that exact block. 
  • The block editor presentations a preview whilst you hover over the button.
  • The Kinds engine attaches the CSS elegance is-blue-border to the block within the editor and at the frontend.
  • When opening the International Kinds by way of Kinds → Blocks → Symbol, the types will also be modified by way of the person for the entire website. 

To prepare your block genre code, you’ll create a subfolder within the types folder known as /blocks and stay all of them in combination. A couple of theme builders discovered they might scale back the period in their purposes.php document significantly by way of enforcing subfolders as a substitute.

Approach 2: sign up block genre in PHP and magnificence it by way of theme.json

  • Absolute best for: Theme builders
  • The place you could possibly usually use it: Within the theme.json document and in purposes.php
  • Model necessities: WordPress 6.6 or upper with theme.json v3 

So as to add a customized block genre the use of this system, you’ll wish to sign up the way and upload your stylings within the theme.json document.

Sign up block genre 

To your purposes.php document, use the register_block_style() serve as to set the 2 necessary arguments (further not obligatory arguments are lined under): 

  • title: The identifier of the way used to compute a CSS elegance.
  • label: A human-readable label for the way.

As soon as set, you’ll upload them to the init hook for your theme. 

serve as my_style_red(){

   register_block_style(
       'core/picture',
       array(
           'title'  => 'red-border',
           'label' => __( 'Purple Border', 'my-theme' )
       )
   );
}
add_action( 'init', 'my_style_red' );

Upload styling to theme.json

We’ll upload some styling for the red-border variation to the theme.json document. It’s positioned inside the types.blocks.core/picture phase, as we’re making adjustments to the Symbol block.

"types": {
       "blocks": {
           "core/picture":{
               "permutations": {
                   "red-border":{
                       "border": {
                               "colour":"#cf2e2e",
                               "genre": "forged",
                               "width": "4px",
                               "radius":"15px"
                       }
                   }
               }
           },

Those two code snippets paintings in combination since the title used within the register_block_style() serve as for your purposes.php document and the differences’ title arguments for your theme.json document are equivalent. 

This technique produces the similar editor and frontend effects as the use of a JSON document within the /types folder:

  • The manner will likely be visual within the editor and at the frontend. 
  • It is usually to be had by way of the Editor → Kinds → Blocks → Symbol phase for international customization.
a red border around an image block in the Global Styles in WordPress

If the types to be had in theme.json aren’t sufficient, you will have a couple of choices: 

  • You’ll use the CSS assets in JSON notation. The WordPress.org per-block CSS with theme.json article supplies a excellent abstract of the way to try this. 
  • You’ll use any of the strategies under and upload them in your purposes.php document. 
  • You’ll sign up the block genre by way of register_block_style() and come with the CSS for your theme’s total genre.css document, referencing the block and magnificence elegance title. That being stated, this isn’t advisable as those types will at all times load, despite the fact that the block isn’t in use. A worm may be combating the types from loading at the frontend.
  • You’ll use block stylesheets to just load the types when the block is used, as defined within the WordPress Theme manual instructional on block stylesheets. 

Approach 3: upload a block genre with register_block_style() (PHP)

The register_block_style() serve as has 3 further and not obligatory parameters. They’re indexed at the documentation web page for the WP_Block_Styles_Registry elegance that handles the registration and control of block types.

  • style_data: A theme.json-like object used to generate CSS.
  • inline_style: Inline CSS code that registers the CSS elegance required for the way.
  • style_handle: The maintain of a in the past registered genre to enqueue along the block genre.

See the documentation for register_block_style() for more info.

3a. Use the style_data parameter

  • Absolute best for: Plugin builders and theme builders
  • The place you could possibly usually use it: In plugin recordsdata or purposes.php 
  • Model necessities: WordPress 6.6 or upper

Despite the fact that block types had been a elementary manner that WordPress works since 5.0, the style_data parameter used to be added in WordPress 6.6. 

This technique for outlining block types makes use of “a theme.json-like object,” which means an array of nested types in a structure that very carefully resembles the types phase of the theme.json document. On the root stage, the types are implemented to the block(s) that you just outline with the block_name array. 

In case you are aware of theme.json construction, you’ll use this system so as to add further types. This technique permits the ones types in Editor → Kinds → Blocks and customers could make adjustments there. 

As you’ll see, the array notation for this parameter follows JSON carefully. 

The theme.json reads:

"border": {
             "colour":"#cf2e2e",
             "genre": "forged",
             "width": "4px",
             "radius":"15px"
          }

The array in PHP reads:

array(
       'border' => array(
       'colour' => '#f5bc42',
       'genre' => 'forged',
       'width' => '4px',
       'radius' => '15px'
      ),

To additional exhibit this concept, this serve as provides an orange border with a field shadow the use of the “sharp” shadow genre preset. 

serve as my_orange_border() {

   register_block_style(
       array( 'core/picture' ),
       array(
           'title'         => 'orange-border',
           'label'        => __( 'Orange Border', 'pauli' ),
           'style_data'=> array(
                           'border' => array(
                           'colour' => '#f5bc42',
                            'genre' => 'forged',
                            'width' => '4px',
                            'radius' => '15px'
                           ),
                       'shadow' => array(
                           'var(--wp--preset--shadow--sharp)'
                           )
                       )

           )
   );
};

add_action( 'init', 'my_orange_border' );
An Orange Border style selected in the Styles panel and the orange border showing on the image in the WordPress editor

Of the 3 parameters, simplest the style_data knowledge will likely be added to the worldwide genre phase within the website editor and will also be edited by way of the website proprietor. The opposite two upload the types to the Kinds panel, and there is not any edit trail inside the UI.

3b. Use the inline_style parameter

  • Absolute best for: Plugin builders and theme builders
  • The place you could possibly usually use it: In the principle plugin PHP document or purposes.php
  • Model necessities: WordPress 5 or upper

The price for the inline_style parameter is a mixture of the CSS selector and the CSS homes.

serve as my_double_frame_styles() {
   register_block_style(
       'core/picture',
       array(
           'title'         => 'double-frame',
           'label'        => __( 'Double-Body', 'pauli' ),
           'inline_style' => '.wp-block-image.is-style-double-frame
                               img { border: 10px ridge lightgreen; }'
       )
   );
}
add_action( 'init', 'my_double_frame_styles' );
A Double Frame style selected in the Styles panel and the green border showing on the image in the WordPress editor

The category title follows same old block editor naming conventions. Every core block’s elegance title incorporates the prefix wp-block + the block title, like picture. It’s then adopted by way of the block genre prefix is-style and the registered genre slug, like double-frame.

The category title .wp-block-image.is-style-double-frame is adopted by way of the way that you need to connect to the block. Right here you spot the CSS values for the border assets for the picture component (img). It provides a ridged, mild inexperienced 1px border. 

You’ll have rather a couple of CSS homes blended within the inline_style parameter for the serve as, however it’s going to transform laborious to learn and arrange.

3c. Use the style_handle parameter

  • Absolute best for: Plugin builders and theme builders
  • The place you could possibly usually use it: In plugin recordsdata or purposes.php
  • Model necessities: WordPress 5 or upper

For extra elaborate types, imagine putting the CSS in a separate document and the use of wp_enqueue_style() to load it at the frontend and backend. Then use the style_handle parameter within the register_block_style() serve as. 

Right here is a few instance code the use of this system so as to add a crimson border genre.

serve as 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/picture',
       array(
           'title'         => 'purple-border',
           'label'        => __( 'Red Border, reasonably rounded', 'pauli' ),
           'style_handle' => 'my-image-block-style'
       )
   );
}

And here’s the accompanying my-purple-border.css document, which is positioned into the plugin’s root folder.

.is-style-purple-border img {
   border: 6px forged crimson;
   border-radius: 15px;
   box-shadow: 10px 5px 5px #e090fc;
};

The picture block now has a crimson border with a pinkish shadow genre. 

A purple border style selected in the Styles panel and the purple border showing on the image in the WordPress editor

Observe: There may be a worm document open in regards to the stylesheet loading even if the block types aren’t used. As a result of this, it’s now not advisable for complicated CSS.

Approach 4: sign up block types the use of JavaScript + CSS

  • Absolute best for: Plugin builders and theme builders
  • The place you could possibly usually use it: In a separate *.js document, enqueued in a plugin document, or in purposes.php
  • Model necessities: WordPress 5 or upper

In comparison to the use of the separate JSON document so as to add a block genre variation, the use of JavaScript is extra elaborate. It has 3 portions: 

  • PHP: To enqueue the essential recordsdata
  • JavaScript: To sign up the block genre
  • CSS: To genre the block

The wp_enqueue_script() serve as provides JavaScript recordsdata to a webpage. It’s now not JavaScript itself, however quite a WordPress PHP serve as that’s incessantly utilized in WordPress theme or plugin building. For this situation, we will be able to retailer the .js document within the theme’s /js/ subdirectory and title it curate-core.js

The instance code so much our customized curate-core.js document after the essential WordPress block editor scripts. It’s added to the ground of the web page for higher efficiency and is hooked into enqueue_block_editor_assets so it simplest so much within the editor. 

This code instance is going into the theme’s purposes.php document or your plugin’s *.php document. 

serve as 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( 'Model' ), true
       );
       }
      
add_action( 'enqueue_block_editor_assets', 'pauli_block_editor_scripts' );

This code will have to pass within the JavaScript document curate-core.js:

wp.domReady( serve as() {
   
   wp.blocks.registerBlockStyle(
       'core/picture', {
           title: 'black-border',
           label: 'Black Border',
       }
   );

} );

You’ll then upload our block types in your theme’s genre.css document the use of the mechanically added elegance title, is-style-black-border.

.is-style-black-border img {
   border: 15px ridge black;
}

Because of a worm, you wish to have so as to add the genre.css to the frontend. It doesn’t appear to be mechanically loaded. You utilize wp_enqueue_style() after which use the hook wp_enqueue_scripts.

Then you definitely’d upload the next in your purposes.php or plugin document:

serve as enqueue_theme_styles() {
   wp_enqueue_style(
       'my-theme-styles',
       get_stylesheet_uri(), // This will get your genre.css
       array(),
       wp_get_theme()->get( 'Model' )
   );
}
add_action( 'wp_enqueue_scripts', 'enqueue_theme_styles' );

You additionally wish to upload genre.css to the block editor so your customers can see how the block genre seems when they’re operating at the put up or web page. 

//upload genre.css to editor
serve as add_theme_editor_styles() {
   add_editor_style( 'genre.css' );
}
add_action( 'after_setup_theme', 'add_theme_editor_styles' );
A black border style selected in the Styles panel and the black border showing on the image in the WordPress editor

Non-compulsory: casting off undesirable core block types

Now that you know the way to upload block types in your theme or your plugin, you may also need to take away some further block types that include the block editor out of the field.

There are two purposes you’ll wish to deal with: 

Block types can simplest be unregistered in the similar coding language used to sign up them. All core blocks are registered with JavaScript. 

The instance code under gets rid of the extra block genre for the picture block known as rounded.

wp.domReady( serve as() {
   wp.blocks.unregisterBlockStyle( 'core/picture', [ 'rounded' ] );
} );

For extra techniques to change the block editor, learn 15 techniques to curate the WordPress modifying enjoy.

Abstract: customized block types at a look

You presently know the six techniques to sign up block types for the WordPress block editor. Right here’s a handy guide a rough recap of what we lined:

Block Taste Added in Instance Code Language Theme/Plugin Parameter Report International Kinds
🟥 Purple  PHP+  Theme theme.json sure
🟦 Blue  JSON Theme image-blue-border.json sure
🟧 Orange  PHP Theme/Plugin style_data sure
🟪 Red PHP Theme/Plugin style_handle .css no
🟩 Double Body  PHP  Theme/Plugin inline_style no
⬛ Black  JS Theme/Plugin .js + .css + .php no

The perfect manner is so as to add a JSON document to the /types folder the use of the theme.json structure. An alternative choice makes use of minimum PHP for your purposes.php document along your theme.json configuration. Each approaches upload block types to the Kinds panel within the editor, the place customers can follow and customise them.

Plugin builders can use the style_data parameter to succeed in identical effects, together with integration with International Kinds.

Different plugin-based strategies—the use of inline_style, style_handle, or JavaScript—don’t fortify International Kinds modifying, however nonetheless make the types selectable within the editor.

Remember that the primary 3 strategies (JSON document, theme.json with PHP, and style_data) require WordPress 6.6 or upper. To fortify older WordPress variations, you’ll wish to use one of the vital different to be had approaches.

Assets to be informed extra

Wish to be told much more about block types and block permutations? Listed here are some assets to take a look at: 

YouTube

Make.WordPress Dev Observe

WordPress Developer Weblog

Block Editor Guide

Subject matters Guide 

WPBeginner Highlight 27: WordPress 7.1, WPVibe AI All over, and a New Option to Report Your Display
WPBeginner Highlight 27: WordPress 7.1, WPVibe AI All over, and a New Option to Report Your Display by in Blog

August used to be a large month for WordPress. WordPress 7 ...

01 Sep, 2026 7  Person Liked it

WordPress.com Changelog: A New Web hosting Dashboard, a ChatGPT Plugin, and WordPress 7.1
WordPress.com Changelog: A New Web hosting Dashboard, a ChatGPT Plugin, and WordPress 7.1 by in Blog

August 14 – 27, 2026 Welcome again to the WordPr ...

30 Aug, 2026 7  Person Liked it

Your WordPress.com Website Now Works from Within ChatGPT
Your WordPress.com Website Now Works from Within ChatGPT by in Blog

You'll now set up your WordPress.com web page from Ch ...

27 Aug, 2026 6  Person Liked it

Offer Ends Tonight 12 PM

Lifetime Membership with Unlimited Access