- This topic has 19 replies, 5 voices, and was last updated 4 years, 1 month ago by
David.
-
AuthorPosts
-
February 20, 2021 at 12:36 pm #1665987
Marijke
How can I remove the core patterns? I found on this on github
So I tried:
add_action( 'after_setup_theme', 'mm_remove_patterns' ); function mm_remove_patterns() { remove_theme_support( 'core-block-patterns' ); }but it didn’t work.
Any suggestions?
February 20, 2021 at 3:21 pm #1666057Leo
StaffCustomer SupportHi there,
Is this for removing the core blocks that come with WordPress?
Does that code work in a Twenty series WP theme?
Let me know 🙂
February 21, 2021 at 4:45 am #1666338Marijke
Hi Leo,
Yes, the code works with Twenty Twenty-One. If I use it I only get the twenty-one patterns and not the default. As expected.
thanks,
Marijke
February 21, 2021 at 6:15 am #1666391Marijke
When I try to click on patterns in the editor I get this error.
I also tried on a clean test site with several themes. The same result. Other themes like Astra and Genesis gave the same problem like GeneratePress.February 21, 2021 at 10:19 am #1666796Leo
StaffCustomer SupportSorry I’m a little bit confused.
GP doesn’t add support for block patterns so you shouldn’t need to remove anything?
Let me know if I’m missing something here.
When I search for pattern in the block editor in a default GP install, there is no result:
https://www.screencast.com/t/vwTQ2vsFUAFebruary 21, 2021 at 11:49 am #1666862Marijke
Hi Leo,
WordPress added block patterns in release 5.5. See https://wordpress.com/support/block-pattern/ or https://gutenbergtimes.com/the-wordpress-block-patterns-resource-list/The WordPress core comes with a set of default block patterns, with Don Quixote de La Mancha texts. Justin Tadlock made a plugin (Block Patterns) that helps you make and maintain your own patterns. So I only want to see my own patterns and not the default ones from the core. Those default patterns are visible in GeneratePress and I have problems to remove them. They are not normal blocks, but a set of blocks, just like reusable blocks. Click on the Brows all button and you will see them.
February 21, 2021 at 1:09 pm #1666943Leo
StaffCustomer SupportI see. Thank you for the explanation.
I just added your code using the Code snippet plugin and it worked for me. See the demo here:
https://www.screencast.com/t/CaNIGCFeQFebruary 22, 2021 at 5:06 am #1667542Marijke
Hi Leo,
Yes, it works when you don’t have self made patterns.
Look at my demo:
https://youtu.be/RxWBM64wv4UFebruary 22, 2021 at 11:55 am #1668227Steven
We’re interested in resolving this as well. We’re seeing the same behavior. We can suppress the core patterns, but when we try to create a new pattern using the plugin, the page editor breaks. But we may need to follow up with the block pattern plugin developer instead of GeneratePress. Although the core patterns are being loaded by default with the GeneratePress theme enabled, even though it sounds like GeneratePress isn’t purposely loading them.
February 22, 2021 at 12:35 pm #1668272Steven
This seems to be an issue with the block pattern plugin. When we remove the core patterns, create a new pattern and category using code in the functions.php file, and ensure no patterns have been created by the plugin, it works. Try the following code from https://wpblockz.com/tutorial/how-to-make-a-pattern-in-the-wordpress-gutenberg-editor/#plugin:
//Remove WordPress Core default block patterns add_action( 'after_setup_theme', 'my_remove_patterns' ); function my_remove_patterns() { remove_theme_support( 'core-block-patterns' ); } function my_register_block_patterns() { if (class_exists('WP_Block_Patterns_Registry')) { // register pattern register_block_pattern('mine/your-pattern', [ 'title' => __('Your pattern title', 'textdomain'), 'description' => _x( 'Your pattern description', 'Block pattern description', 'textdomain' ), 'content' => "<!-- wp:paragraph -->\n<p>Your pattern</p>\n<!-- /wp:paragraph -->", 'categories' => ['section'], ]); // register categories register_block_pattern_category('section', [ 'label' => _x('Section', 'textdomain'), ]); } } add_action( 'init', 'my_register_block_patterns' );February 22, 2021 at 12:39 pm #1668279Steven
This is a known bug with the Block Pattern plugin: https://github.com/justintadlock/block-pattern-builder/issues/21
February 22, 2021 at 1:47 pm #1668343Steven
As a temporary workaround, you can remove theme support for block patterns, register a single placeholder pattern and category, and then use the Block Pattern plugin to manage your custom patterns. All of the patterns created with the plugin will fall in a “non-category” of Uncategorized. We tried to uregistering everything and just registering a placeholder category to see if only the Uncategorized patterns would be displayed. But WordPress still shows the category. We also tried naming a category of “Z Default” to see if the Uncategorized would be the default selected category in the pattern picker, but Uncategorized always sorts to the very bottom of the category picker dropdown. What we plan to do until the plugin supports categories is create a simple default category and pattern. Then we’ll prefix all of our custom patterns. That way our users can search for them easily. Not as elegant as we’d like, but more workable than site editors continually forgetting to convert reusable blocks to regular blocks before editing them and nuking the parent reusable block (it’s happened several times in the past week because Gutenburg change the option to convert a reusable block).
// Unregister WordPress Core default block patterns add_action( 'after_setup_theme', 'cob_remove_patterns' ); function cob_remove_patterns() { remove_theme_support( 'core-block-patterns' ); } //Add a default block pattern to address a bug in the Block Pattern plugin until it starts supporting categories function my_register_block_patterns() { if (class_exists('WP_Block_Patterns_Registry')) { // register a placeholder default pattern register_block_pattern('mine/z-Default', [ 'title' => __('Z Default', 'textdomain'), 'description' => _x( 'Default block pattern', 'Block pattern description', 'textdomain' ), 'content' => "default", 'categories' => ['Z Default'], ]); // register placeholder category register_block_pattern_category('Z Default', [ 'label' => _x('Z Default', 'textdomain'), ]); } } add_action( 'init', 'my_register_block_patterns' );February 22, 2021 at 2:30 pm #1668362Steven
Eureka! Use the following plugin: https://wordpress.org/plugins/blockmeister
It’s named the same as the other plugin, but allows management of block pattern categories 😉
Install the plugin and add the following to your functions.php file in your GeneratePress child theme:
//Remove WordPress Core default block patterns add_action( 'after_setup_theme', 'remove_patterns' ); function remove_patterns() { remove_theme_support( 'core-block-patterns' ); }February 22, 2021 at 2:57 pm #1668404Leo
StaffCustomer SupportThanks for sharing the solution Steven!
February 23, 2021 at 1:06 am #1668778Marijke
Wow, thank you very much Steven! This is a great solution. The plugin even has a dutch translation. I am so very happy with this.
-
AuthorPosts
- You must be logged in to reply to this topic.