Disable the Theme's Block Patterns
Removes the patterns bundled with your active theme from the inserter, for sites that only want their own patterns.
Opens WPIDE on
Code
add_action( 'init', function () {
$registry = WP_Block_Patterns_Registry::get_instance();
$prefixes = array_unique( array( get_stylesheet() . '/', get_template() . '/' ) );
foreach ( $registry->get_all_registered() as $pattern ) {
foreach ( $prefixes as $prefix ) {
if ( 0 === strpos( $pattern['name'], $prefix ) ) {
unregister_block_pattern( $pattern['name'] );
break;
}
}
}
}, 99 );
Notes
Patterns from WordPress core and plugins are not affected. Use Disable Core Block Patterns for those.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.