In this part, I want to bring up additional tips, answer common questions, and show you some useful resources.
Let’s recap what we have learnt so far:
A block pattern is created using the PHP function register_block_pattern.
There is also no interface for a user to create a block pattern while working in the editor. This is something that has been brought up and suggested several times, and I believe that it will be added eventually.
An interface for creating patterns would possibly work very similar to how reusable blocks are created.
There are already a few plugins that does this, that may help you speed up the pattern creation. Feel free to try them out, but I do not guarantee that they will work with 5.5, because of the major changes.
Both block patterns and block pattern categories can be unregistered.
To remove all WordPress default block patterns, there is a handy trick that will feel familiar to most theme authors:
remove_theme_support( 'core-block-patterns' );
This needs to be added to an init hook, you will most likely place this inside a function, together with the rest of your theme support.
To remove a single block pattern, use the PHP function unregister_block_pattern, together with the patterns prefix and pattern slug:
unregister_block_pattern( 'prefix/my-awesome-pattern' );
So if you wanted to remove one of the patterns that are included in WordPress, for example the pattern with two buttons, you would use:
unregister_block_pattern( 'core/two-buttons' );
This also works for block patterns created by plugins, all you need is the prefix and name of the pattern.
To remove a category, use the function unregister_block_pattern_category
I have ran into the problem where my pattern markup is invalid countless of times.
Many times, the message that is shown when I try to resolve a block markup error, is not helpful at all.
What I try to do to solve markup problems is:
Finally, re create the pattern in the editor, copy all the code again and hope for the best! 🙂
It depends. Who is the pattern for, what is it for, and how much content is there?
A block pattern with default content can be easier for user to get started with. It may be easier for them to edit content that is already in place, compared to adding new content.
Default local images that are included in patterns, are lost when the user switches themes.
I would say that the best practice is to not include images or video.
We will see how block patterns and best practices evolve over time as more people create them.
By only having an empty placeholder block, the user selects their own image from their media library, and the image does not break if the theme is changed.
But if it is a block that depends on the visual presentation created by the image, then perhaps the user can be informed about how to secure their image.
The following free themes in the WordPress.org theme directory also has block patterns:
Inclusive is made by me, and it is the theme used on this very site.
Example presentation pattern with image:
This is an example placeholder text. Edit it to make it your own.
You can change the image by selecting the block and clicking “Replace”.
This paragraph block uses the secondary background color and the “Rounded corners” style.
Did you know that you can adjust how wide you want your columns to be?
It also has a short presentation of the patterns in the admin area, and a way to copy the pattern code, for sites that are using a WordPress version that does not support block patterns.
Cordero was the second theme in the directory to include block patterns. It has a large number of patterns, including service sections, food menus, and pricing tables.
Deejay is also made by me, but only includes one pattern that helps the user create basic profiles for the artists.
WordPress training has an introduction video for how to find and use block patterns. You can share this with your users so that they can get familiar with how to work with the patterns you have included in your theme or plugin.