Skip to content

Save unedited theme patterns in templates as pattern references #894

Open

Description

@iamtakashi

When a theme pattern is inserted into a template in the Site Editor, the editor adds a full copy of its blocks and marks the root block with metadata.patternName. Saving the template with Create Block Theme writes that copy into the theme file. The theme ends up with the same section twice: once in its own pattern file and once inside the template's pattern.

The two copies drift apart over time. A fix made later to the section pattern never reaches the copy in the template.

Core themes avoid this by building templates from references:

<!-- wp:pattern {"slug":"twentytwentyfive/hero"} /-->

On save, CBT could check each block that has a metadata.patternName pointing to a pattern registered by the active theme. If its content still matches that pattern, CBT would write a wp:pattern reference in its place. Blocks that were edited after insertion would stay inline as they are now.

Related: #872, which covers the patternName metadata that saving leaves behind.

Drafted with AI assistance, reproduced and verified by me.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions