gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Disable Patterns tab

Open christofervas opened this issue 1 year ago • 14 comments

Description

I use the following code to disable the Pattern directory but after upgrading to WordPress 6.6.1 the Patterns tab is showing even without contain any patterns. Is this a bug?

https://developer.wordpress.org/block-editor/how-to-guides/curating-the-editor-experience/disable-editor-functionality/#disable-the-pattern-directory

I also use the following: add_filter( 'should_load_remote_block_patterns', '__return_false' );

Step-by-step reproduction instructions

Add the following code. The Patterns tab is still showing up.

function example_theme_support() {
    remove_theme_support( 'core-block-patterns' );
}
add_action( 'after_setup_theme', 'example_theme_support' );

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • [X] Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • [X] Yes

christofervas avatar Jul 30 '24 10:07 christofervas

Hi These code snippets only disable the patterns added by WordPress core, and the patterns from https://wordpress.org/patterns/. Not the ability to manage patterns added by users, themes or plugins.

carolinan avatar Jul 30 '24 12:07 carolinan

Hey @carolinan thanks for clarifying this. Is there any way to disable the Patterns tab? Even on a clean installation with no patterns installed from theme, core, user etc. the Patterns tab is still shown with a notice "No results found."

christofervas avatar Jul 30 '24 14:07 christofervas

I don't have the answer off the top of my head but it would probably be about changing the permissions for different user roles.

carolinan avatar Jul 30 '24 16:07 carolinan

The code provided didn't worked for me. This one did worked:

function remove_menus_appearance_patterns(){  
    // Appearance > Patterns  
    remove_submenu_page('themes.php', 'site-editor.php?path=/patterns');  
}  
add_action('admin_menu', 'remove_menus_appearance_patterns');

fgbarrios avatar Sep 13 '24 22:09 fgbarrios

The code above only removes the menu item from the WordPress admin menu. Not the patterns tab.

carolinan avatar Sep 15 '24 06:09 carolinan

I have run into this as well. Up until WP v6.6 (Gutenberg v18.5, I think), removing theme support for 'core-block-patterns' did the trick. Now I need to use a CSS hack, which is never reliable. As new versions role out, it's not uncommon for classnames to change.

(On a side note, not related to this ticket, would also like to remove the Media tab, too)

Codeyak avatar Oct 04 '24 12:10 Codeyak

I have run into this as well. Up until WP v6.6 (Gutenberg v18.5, I think), removing theme support for 'core-block-patterns' did the trick. Now I need to use a CSS hack, which is never reliable. As new versions role out, it's not uncommon for classnames to change.

(On a side note, not related to this ticket, would also like to remove the Media tab, too)

I'm confirming this behaviour: it's important to clean Gutenberg interface for customer's site; actually doing through CSS

meksone avatar Nov 11 '24 16:11 meksone

Can you all add more detailed information about what part of the UI you are looking to hide? It is unclear if the same parts of the UI are being discussed here.

carolinan avatar Nov 12 '24 07:11 carolinan

Can you all add more detailed information about what part of the UI you are looking to hide? It is unclear if the same parts of the UI are being discussed here.

Hi, thanks for asking :) I think we are discussing this section of the interface (at least, I want to hide this part): Image

meksone avatar Nov 12 '24 10:11 meksone

I am running into the same thing, did anyone ever get a solution to this?

snibe avatar Dec 04 '24 19:12 snibe

Any updates to this?

rico347 avatar Mar 26 '25 14:03 rico347

Right now I am using the following css for this problem:

.block-editor-tabbed-sidebar__tab[aria-controls*="patterns"], .block-editor-tabbed-sidebar__tab[aria-controls*="media"] { display: none !important; }

rico347 avatar Mar 26 '25 15:03 rico347

@fgbarrios - previous solution doesn't work any longer (5th june, 2025): replace "path" with "p" and "patterns" with "pattern".

// Remove Gutenberg patterns from the menu
function remove_menus_appearance_patterns(){  
    // Appearance > Patterns  
    remove_submenu_page('themes.php', 'site-editor.php?p=/pattern');  
}  
add_action('admin_menu', 'remove_menus_appearance_patterns');

marziodev avatar Jun 05 '25 17:06 marziodev

Right now I am using the following css for this problem:

.block-editor-tabbed-sidebar__tab[aria-controls*="patterns"], .block-editor-tabbed-sidebar__tab[aria-controls*="media"] { display: none !important; }

That worked for me - but I also needed to add some extra CSS to remove the gradient mask on the tabs:

.block-editor-tabbed-sidebar__tablist { mask-image: none !important; }

Web-Assembler avatar Jun 16 '25 15:06 Web-Assembler

It does feel a bit unexpected to have a completely empty patterns tab when there are no patterns available:

Image

Would be good to double-check this one with design folks. Should we hide the tab if there are no patterns? Cc @WordPress/gutenberg-design

tellthemachines avatar Nov 24 '25 23:11 tellthemachines

Should we hide the tab if there are no patterns?

Thanks for the ping, and I'd love to open that question even more broadly. Certainly it's not a good experience to see something permanently empty, but other options are to link to the core pattern directory, or link to the site editor pattern manager. For me it boils down to: what is the spirit of the API? If as Carolina notes it is to disable the core patterns, then the tab should not go away, it should just have a better empty-state. Presumably if you create a pattern yourself, synced or otherwise, then it would show up here.

If we did want an API to disable the patterns tab, IMO that same API should also disable the editor > Manage patterns link, the site editor Patterns section, the ability to create a pattern (both synced and unsynced), because all of those entrypoints would each be similarly confusing, as an empty inserter tab is. And this feels like a fairly wide-reaching API that I'm not sure is actually what we want.

jasmussen avatar Nov 25 '25 07:11 jasmussen

Thanks for the prompt reply @jasmussen!

I wasn't thinking of an API to disable the patterns tab because as you say that would require disabling patterns everywhere in order to work well. But we could perhaps only show the patterns tab if there are any patterns to show, instead of showing it empty. Then, as soon as the user created a pattern, or switched to a theme with patterns, the tab would reappear. I haven't looked into how straightforward that would be to implement yet, just wondering whether it's something we might want to do.

tellthemachines avatar Nov 25 '25 22:11 tellthemachines

Yep, that's valid, I'm just not sure what problem it solves. The patterns menu item will still be there even if your theme doesn't have any patterns, and it boils down to the fact that patterns are enabled as a feature: you can create your own, synced and unsynced. The theoretical benefit of disabling the tab is that a small interface of the editor is cleaner for people who do not use the feature at all. But it's at the cost of a little bespoke conditional code for just that, and the potential opportuntity cost that people don't learn about what patterns can do, which especially if the contentOnly changes graduate from experimental, really elevate the experience. From that perspective, the missing opportunity here is to show something better—even clearer help text that explains the what and why of patterns—in the empty patterns tab.

jasmussen avatar Nov 26 '25 08:11 jasmussen

Ok that makes sense! Let's give the patterns feature some more time to mature before hiding any UI. I'll go ahead and close this one for now. Thanks everyone!

tellthemachines avatar Nov 26 '25 22:11 tellthemachines