Block Editor PHP Beginner

Remove Default Block Patterns from the Inserter

Remove WordPress's built-in block patterns and the patterns it downloads from WordPress.org, so the inserter only shows your own.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 17 lines
// Remove the patterns bundled with WordPress core.
add_action( 'after_setup_theme', function (): void {
	remove_theme_support( 'core-block-patterns' );
} );

// Stop loading patterns from the WordPress.org pattern directory.
add_filter( 'should_load_remote_block_patterns', '__return_false' );

// Catch any remaining core/* patterns, whatever they are called in this version.
add_action( 'init', function (): void {
	$registry = WP_Block_Patterns_Registry::get_instance();
	foreach ( $registry->get_all_registered() as $pattern ) {
		if ( str_starts_with( $pattern['name'], 'core/' ) ) {
			unregister_block_pattern( $pattern['name'] );
		}
	}
}, 20 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

The block inserter’s Patterns tab mixes three sources: patterns bundled with WordPress, patterns downloaded from the WordPress.org directory, and the ones your theme and plugins register. On client sites the first two are mostly noise. This snippet removes them so only your own patterns remain.

How it works

Removing the core-block-patterns theme support stops WordPress registering its bundled patterns. The should_load_remote_block_patterns filter stops the editor fetching patterns from WordPress.org, which also removes a remote request each time the editor loads.

The last part loops over every registered pattern and removes any whose name starts with core/. The old version of this snippet listed pattern names by hand. WordPress renames and replaces core patterns between releases, and unregistering a name that doesn’t exist triggers a “called incorrectly” notice. Reading the registry avoids both problems.

What stays

Patterns registered by your theme (including files in its /patterns folder), by plugins and the synced patterns you create in the editor are not touched. To remove a theme’s patterns too, change the check to match its prefix, for example str_starts_with( $pattern['name'], 'twentytwentyfive/' ).

How to test it

Open the block editor, click the inserter and choose Patterns. The WordPress categories such as “Query” or “Featured” should be gone, and your theme’s patterns should still be there.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only