Skip to content

Add support for replacing "general" template parts #44689

@inc2734

Description

@inc2734

Description

Define your own template part area. Then, create multiple template parts that belong to that area. Open the site editor and insert one of the template parts you created.

At this point, in WordPress 6.0, you will see "Replace" in the toolbar of that template part, but not in 6.1.

It does not appear even after activating the Gutenberg plugin.

Step-by-step reproduction instructions

Since it is necessary to define the template parts area and create the template parts file, TT2 is used as an example.

1. Add code to functions.php.

function tt2_default_wp_template_part_areas( $default_area_definitions ) {
	return array_merge(
		$default_area_definitions,
		array(
			array(
				'area'        => 'tt2/template-part/test',
				'label'       => 'Test template parts',
				'icon'        => 'layout',
				'description' => '',
				'area_tag'    => 'div',
			),
		)
	);
}
add_filter( 'default_wp_template_part_areas', 'tt2_default_wp_template_part_areas' );

2. Create template parts.

Open /parts. And create this files.

/parts/test-1.html

<!-- wp:paragraph -->
<p>Test 1</p>
<!-- /wp:paragraph -->

/parts/test-2.html

<!-- wp:paragraph -->
<p>Test 2</p>
<!-- /wp:paragraph -->

3. Add code to theme.json.

	"templateParts": [
		// omission,
		{
			"name": "test-1",
			"title": "Test 1",
			"area": "tt2/template-part/test"
		},
		{
			"name": "test-2",
			"title": "Test 2",
			"area": "tt2/template-part/test"
		}
	]

4. Add template part on the site editor.

スクリーンショット 2022-10-05 8 51 20

スクリーンショット 2022-10-05 8 51 42

In 6.0, "Replace" appears on the toolbar.

スクリーンショット 2022-10-05 8 52 00

スクリーンショット 2022-10-05 8 52 20

Not shown in 6.1.

スクリーンショット 2022-10-05 8 53 29

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.1 beta3
  • WordPress 6.0.2
  • Gutenberg 14.2.0

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

Yes

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

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions