Page creation patterns in WordPress 6.0

When a user creates a page, the editor starts with an empty canvas. However, that experience may not be ideal, especially since there are often possible patterns the user can use when creating a page, e.g., an about page, a contact page, a team page, etc.

Starting with WordPress 6.0, offering a set of patterns that users can choose from to create their pages is possible. We added a modal that shows possible patterns that can be used on page creation:

The modal appears each time the user creates a new page when there are patterns on their website that declare support for the core/post-content blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. types. By default, WordPress 6.0 CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. does not include any of these patterns, so the modal will not appear without some of these post content patterns being added.

Any theme or pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party can register a pattern with core/post-content block support and make the modal with the patterns appear. Here we provide a sample pattern that appears in this model.

register_block_pattern(
	'my-plugin/about-page',
	array(
		'title'      => __( 'About page', 'my-plugin' ),
		'blockTypes' => array( 'core/post-content' ),
		'content'    => '<!-- wp:paragraph {"backgroundColor":"black","textColor":"white"} -->
		<p class="has-white-color has-black-background-color has-text-color has-background">Write you about page here, feel free to use any block</p>
		<!-- /wp:paragraph -->',
	)
);

To register the page patterns via the theme.jsonJSON JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. file added the Body Types section to the php stub:

<?php
 /**
  * Title: Hello
  * Slug: my-theme/hello
  * Block Types: core/post-content
  * Categories: featured, text
  */
?>
<!-- wp:heading -->
  <h2>Hello</h2>
<!-- /wp:heading -->

More details on the auto-detection of patterns via .php files, are available in this Dev Notedev note Each important change in WordPress Core is documented in a developers note, (usually called dev note). Good dev notes generally include a description of the change, the decision that led to this change, and a description of how developers are supposed to work with that change. Dev notes are published on Make/Core blog during the beta phase of WordPress release cycle. Publishing dev notes is particularly important when plugin/theme authors and WordPress developers need to be aware of those changes.In general, all dev notes are compiled into a Field Guide at the beginning of the release candidate phase.: New features for working with patterns and themes in WordPress 6.0

Completely disabling this functionality

By default, no modal appears because there are no post-content patterns unless a theme or plugin registers one.
If one wants to disable the modal even if there are plugins registering post-content patterns, it is possible to do so by removing the post-content block type from all patterns, as the following code sample does:

$patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
foreach ( $patterns as $pattern ) {
	if (
		! empty($pattern['blockTypes'] ) &&
		in_array('core/post-content', $pattern['blockTypes'] )
	) {
		unregister_block_pattern( $pattern['name'] );
		$pattern['blockTypes'] = array_diff( $pattern['blockTypes'], array( 'core/post-content' ) );
		register_block_pattern( $pattern['name'], $pattern );
	}
}

For more info see #40034.

#6-0, #dev-notes, #dev-notes-6-0