Update: this feature has been punted to WordPress 7.0
A recent update to the Site Editor template management system has significantly enhanced WordPress template management by providing greater flexibility and control over the template editing experience. It is now possible to view created templates separately from theme templates, store more than one template per template type (or slug), edit templates and save them without making them active, manage template revisions more effectively, and mark specific templates as active or inactive according to requirements.
For more context on the history behind this change, read through the following proposal on GitHub
Key Changes
- Template Management: Allows multiple templates with the same target slug and introduces the ability to switch between them by setting one as “active.”
- Theme templates remain the “source of truth”: To edit a theme template, one first needs to create a duplicate of it as a Created Template and edit that template.
- Theme Template Control: Users can now disable theme templates (except the essential index template)
- New UI: Adds “Active templates” and “Created Templates” views in the Site Editor
- API Simplification: User templates now use standard Post Type REST API endpoints
- Enhanced Features: Enables revisions, duplication, and trashing through normal Post actions
Benefits
- Created templates are retained when switching themes
- Users can disable template edits when needed
- New templates can be created without immediately publishing
- Templates can be added for all slugs, not just missing ones
- Improvements to template revisions, template duplication, and deleting templates
- And more. For full details, see the PR description
Testing Instructions
- Install and activate the Gutenberg Nightly plugin from Gutenberg Times, or use this Playground link
- Navigate to Site Editor > Templates and test the new template management features
- Verify that you can see template categories for Active, Custom, and theme templates.
- Test custom theme templates
- Create, edit, and save a custom theme template, and confirm it only appears in the Created templates list.
- Test active templates
- Create multiple templates for the same target slug (ie, single-post) and ensure you can activate/deactivate different templates, and that the front-end rendering uses the correct template.
- Confirm that when activating one template, the other templates for that slug are marked as inactive.
- Test that you can activate a template in the template editing view.
- Test default template fallback
- Deactivate a theme template and ensure the correct fallback template (in line with the template hierarchy) is used instead.
- Test switching themes
- Once you’ve created a custom template, switch to a different block theme and ensure the custom template remains.
- Test that template revisions, duplicating templates, and deleting templates work as expected.
Testing Steps
Breaking Changes
- Changes to
getEditedPostIdandgetCurrentPostIdmay impact plugins - Plugins should migrate to use
getEditedPostSluginstead
Logging bugs and discussions
All existing bugs are being tracked in the following tracking issue in the Gutenberg GitHub repository: https://github.com/WordPress/gutenberg/issues/71735
If you encounter any new bugs related to this feature during testing, please log them as new issues and mention them in the above tracking issue.
If you’re unsure whether what you are experiencing is a bug, you can ask in the #outreach channel on the WordPress Slack.
+make.wordpress.org/core, +make.wordpress.org/themes
Props to @krupajnanda, @annezazu, @bph, and @juanmaguitar for assistance in reviewing this post.