Site logo

[Support request] remove core patterns

Home Forums Support [Support request] remove core patterns

Home Forums Support remove core patterns

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #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?

    #1666057
    Leo
    Staff
    Customer Support

    Hi 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 🙂

    #1666338
    Marijke

    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

    #1666391
    Marijke

    When I try to click on patterns in the editor I get this error. editor 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.

    #1666796
    Leo
    Staff
    Customer Support

    Sorry 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/vwTQ2vsFUA

    #1666862
    Marijke

    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.
    patterns

    #1666943
    Leo
    Staff
    Customer Support

    I 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/CaNIGCFeQ

    #1667542
    Marijke

    Hi Leo,
    Yes, it works when you don’t have self made patterns.
    Look at my demo:
    https://youtu.be/RxWBM64wv4U

    #1668227
    Steven

    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.

    #1668272
    Steven

    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' );
    #1668279
    Steven

    This is a known bug with the Block Pattern plugin: https://github.com/justintadlock/block-pattern-builder/issues/21

    #1668343
    Steven

    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' );
    #1668362
    Steven

    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' );
    }
    #1668404
    Leo
    Staff
    Customer Support

    Thanks for sharing the solution Steven!

    #1668778
    Marijke

    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.

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.