As WordPress expands its core block library, developers, designers, and content creators have powerful, out-of-the-box tools to create beautiful content efficiently. By structuring a site’s content around core blocks, we can improve everything from design to development and accessibility. By leveraging core WordPress blocks, we bring the creation process from good to great.
Having a set of well tested core blocks at our fingertips is an amazing starting point, but to really take advantage of those tools we have available to us we need to understand what blocks do, how blocks work, and how blocks can be customized.
What blocks do
In WordPress, Gutenberg blocks define the structure of a page, offering everything from simple text and images to complex layouts like grids and galleries.
Adding a block to the editor determines the markup that will be rendered on the page. One key advantage of using blocks is the ability to preview the layout as you write content, ensuring better visual consistency between the editor and the frontend.
How blocks work
A Gutenberg block consists of predefined markup, settings, and styles. When a user modifies a block, those settings are stored in an HTML comment as a JSON object, ensuring they persist when the block is edited later. On the frontend, the block is rendered by reading these settings as block attributes.
There are numerous benefits to working with blocks, such as the ease of re-ordering content, duplicating blocks, customizations, and creating content templates, also known as block patterns.
How can blocks be customized
While the default settings and styles of the blocks provided by WordPress are powerful, a custom design often incorporates layouts that may not be achievable with only the core blocks. This is where we look at leveraging core WordPress blocks to extend their functionality, layout, and styles.
When you customize blocks, you can modify their markup or add extra settings to pass custom block attributes to the frontend.
View the repo on GitHub to follow along and test these customizations in your own testing environment.
- Check out the repo [here] (github.com/rareview)
- For quick and easy local testing, checkout [Studio by WordPress.com] (developer.wordpress.com/studio)
Block variations
One way to customize a core block is to create a [block variation] (developer.wordpress.org/themes/features/block-variations). A block variation is essentially a copy of a block type that you customize to have a different set of default behaviors.
For example, you can create a variation of the group or cover block and use it as a page hero. While this is a more simple and straightforward example, it demonstrates what is possible for a simple block variation.
Here’s an example:
const { registerBlockVariation } = wp.blocks;
registerBlockVariation(
'core/group',
{
name: 'page-hero',
title: 'Page Hero',
attributes: {...},
innerBlocks: [...],
},
);
Block styles
Another way to customize a core block is to register a [block style] (developer.wordpress.org/themes/features/block-style-variations). A block style is essentially a shortcut for including a class on a block which, in turn, you can attach custom styles or functionality to. A limit to this type of customization, though, is you are only able to apply one block style per block.
For example, you can register a block style to the group block called “Outlined.” When you choose to apply the Outlined block style, the block receives a class of is-style-outlined
. You can apply custom styles to this class in your CSS, allowing users to easily apply the style without remembering the class name or searching through documentation.
Here’s an example:
const { registerBlockStyle } = wp.blocks;
registerBlockStyle(
'core/group',
[
{
name: 'outlined',
label: 'Outlined',
},
],
);
Another example would be to register a “Slider” block style which, in turn, allows you to attach custom JavaScript to enable slider functionality when the class is present.
Block filters
[Block filters] (developer.wordpress.org/block-editor/reference-guides/filters/block-filters) offer a flexible middle ground between variations and styles. They allow developers to register additional settings for a block—whether by adding a simple class or injecting custom markup.
One of my go-to block filters is improving the responsive behavior of the columns block. WordPress handles desktop and mobile layouts well, but it lacks an in-between step for small desktop or landscape tablet views. By registering a filter that applies a class for “Small desktop has two columns,” we can bridge this gap, ensuring better layouts across breakpoints.
This example is longer, [check it out here] (github.com/rareview/leveraging-core-blocks/blob/main/assets/js/blocks-demo)
Block patterns
A block pattern is a pre-defined set of block content that serves as a template, providing fully built components in the editor that only require asset or content updates. You can convert them into synced patterns, which automatically reflect updates wherever the pattern appears.
A block pattern can include any combination of blocks, along with their customizations. In many cases, block patterns streamline workflows by offering ready-made layouts that users can quickly reuse.
Choosing the right customization
Choosing how to customize a block comes down to two key factors:
- Ease of use for the user
- Time required for implementation
While a custom block offers complete control, it requires more time, effort, and testing. On the other hand, a plugin might provide an instant solution, but it also introduces potential security vulnerabilities and performance overhead. In many cases, leveraging core WordPress blocks strikes the best balance between flexibility and efficiency.
There are multiple ways to solve the same problem. For example, a block variation might serve as a quick way to create a pre-configured block, whereas a block pattern could be useful for grouping multiple blocks into a reusable template. The right choice depends on the complexity of the customization and how frequently you will use it.
Customizing blocks is easy, but doing it right means ensuring they’re intuitive for everyone. From interns adding their first post to experienced admins, the experience should be easy. The best customizations feel like a natural extension of the editor, not an extra layer of complexity.
By applying these techniques, we can extend core blocks in a way that enhances functionality while keeping the editing experience intuitive for users.