Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 5, 2025

What?

Resolves #71888

Backports the Core patch WordPress/wordpress-develop#10248 to Gutenberg.

These changes ensure that patterns returned in registered theme templates have pattern metadata, so that themes that use patterns automatically opt into the content only behaviour.

Registered theme patterns are returned from the /wp/v2/registered-templates endpoint.

In Core this is done in WP_REST_Registered_Templates_Controller

In Gutenberg it's done using the get_block_template* filters.

TODO

Why?

Content Only will be released in the plugin before Core (probably 7.0) so we need these changes so the content only feature can be properly tested.

How?

Modifies the resolve_pattern_blocks function to include metadata for single-root patterns, allowing the pattern name and title to be stored in the block attributes. The metadata contains the patternName and name attributes.

This enables identification of patterns inside templates and allows for special treatment in the editor.

Testing Instructions

Check out this PR and head over to /wp-admin/admin.php?page=gutenberg-experiments to enable the contentOnly: Make patterns contentOnly by default upon insertion experiment.

Screenshot 2025-11-05 at 2 25 21 pm

I'm using TT4 to test.

Head over to /wp-admin/site-editor.php?p=%2Ftemplate

In the browser network console, you can check the response of /wp/v2/registered-templates to see if the template content contains pattern metadata (search for metadata)

Now edit the All Archives template (or any that contains a pattern).

In the list view, check that the post 3 col pattern is in content only mode, that is, that it only displays text and other blocks (not containers and so on)

Screenshots or screencast

Before After
Screenshot 2025-11-10 at 12 38 42 pm Screenshot 2025-11-10 at 12 36 33 pm

@ramonjd ramonjd requested a review from spacedmonkey as a code owner November 5, 2025 03:34
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: talldan <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ramonjd ramonjd self-assigned this Nov 5, 2025
ramonjd added a commit that referenced this pull request Nov 5, 2025
@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Nov 5, 2025
@ramonjd ramonjd changed the title Starting to backport WordPress/wordpress-develop#10248 to GB contentOnly patterns: mark patterns as contentOnly by adding metadata.patternName to the root block Nov 5, 2025
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Flaky tests detected in e76d2a4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19220458596
📝 Reported issues:

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the code change looks good to me! In terms of testing the 404 template, something I noticed in practice is that some themes can be a little granular when it comes to their use of patterns. For example, TwentyTwentyFour theme deviates slightly from what we'd expect:

  • The root 404.html contains the twentytwentyfour/hidden-404 pattern, which doesn't use a root container block, so the blocks in the pattern aren't in content only mode
  • However, within that pattern it uses a twentytwentyfour/hidden-search pattern which does contain a single block.... a single Search block. Which behaves a little weirdly (see at the end of this video):
2025-11-05.16.22.29.mp4

This behaviour isn't specifically to do with this PR (i.e. it's more about how content only works currently) so not a blocker to landing this change IMO. It'll also make it easier for us to test, debug, and iterate on contentOnly and how it works with theme patterns, so I think this would be a good one to get in.

Left a similar comment as to the upstream change about potentially merging the metadata value if one exists, but otherwise LGTM!

@ramonjd
Copy link
Member Author

ramonjd commented Nov 5, 2025

In terms of testing the 404 template, something I noticed in practice is that some themes can be a little granular when it comes to their use of patterns.

Thanks for testing @andrewserong

I'll try to track down a better example, but yeah there's going to be some variation. I guess so long as the metadata is added to the block, content only will kick in.

The unit tests prove it, but it'd nice to play with a real one!

@ramonjd
Copy link
Member Author

ramonjd commented Nov 5, 2025

Hol up!

I'll refactor this once the following is in:

@ramonjd
Copy link
Member Author

ramonjd commented Nov 6, 2025

I'll try to track down a better example, but yeah there's going to be some variation.

Might be a good one:

https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-content/themes/twentytwentyfour/templates/archive.html

Uses:

https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-content/themes/twentytwentyfour/patterns/posts-3-col.php

I'll test when I come back to rebase/refactor this on top of #73025

@talldan
Copy link
Contributor

talldan commented Nov 7, 2025

However, within that pattern it uses a twentytwentyfour/hidden-search pattern which does contain a single block.... a single Search block. Which behaves a little weirdly (see at the end of this video):

There was a discussion somewhere (can't find it now) about being able to mark some patterns so that we skip applying the patternName. Maybe this is a good example of that. It could be as simple as some metadata inside the pattern file (contentOnly: false?).

@ramonjd
Copy link
Member Author

ramonjd commented Nov 8, 2025

mark some patterns so that we skip applying the patternName. Maybe this is a good example of that. It could be as simple as some metadata inside the pattern file (contentOnly: false?).

Where's the best place to do this? Assuming the frontend, where there's already logic to detect content only blocks inside a section?

@andrewserong
Copy link
Contributor

I like the idea of patterns being able to opt-out. That said, I was wondering the other day if we should infer it, something like if the pattern doesn't contain any content blocks, then we default to default editing mode for the pattern? But I imagine this is something we could play around with after this PR lands?

…ts to ensure controller returns expected content.
@ramonjd ramonjd force-pushed the try/add-metadata-to-template-patterns-wpdev-10248 branch from 8409ed1 to 91f2b5a Compare November 10, 2025 02:05
@ramonjd
Copy link
Member Author

ramonjd commented Nov 10, 2025

@ramonjd
Copy link
Member Author

ramonjd commented Nov 10, 2025

Okay this is ready for a final test after the migration to filters.

Thanks for the help so far, folks!

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still testing well for me after the refactor! The Archive template is indeed a good example. Also interesting looking at real world patterns as this particular pattern uses a separate paragraph for the separator character () and the text by within a Row block. I suspect we'll encounter a few of these interesting cases where patterns are sometimes a lot more granular with paragraph blocks than we might expect.

image

Just left a couple of comments about ways to possibly improve the tests, but nothing that's a blocker IMO. I reckon this is good to merge and try out!

…s to verify resolved pattern blocks contain expected metadata attributes.
…keys are preserved while updating defined fields. Improved comments for clarity.
…rrect attribute order in the generated HTML.
… preservation. Introduced 'core/with-custom-metadata' pattern and ensured its attributes are correctly resolved in tests.
@ramonjd ramonjd merged commit a7ebbc0 into trunk Nov 10, 2025
36 checks passed
@ramonjd ramonjd deleted the try/add-metadata-to-template-patterns-wpdev-10248 branch November 10, 2025 05:04
@github-actions github-actions bot added this to the Gutenberg 22.1 milestone Nov 10, 2025
@talldan
Copy link
Contributor

talldan commented Nov 17, 2025

Where's the best place to do this? Assuming the frontend, where there's already logic to detect content only blocks inside a section?

@ramonjd I don't think we need to detect content only blocks inside a pattern ... we'd skip adding patternName to blocks if the pattern is opted-out. So wherever patternName is being added would require the check.

@ramonjd
Copy link
Member Author

ramonjd commented Nov 17, 2025

I don't think we need to detect content only blocks inside a pattern

Thanks @talldan

I see you've already updated #73124 with a note 🙇🏻

ramonjd added a commit that referenced this pull request Nov 21, 2025
…o extend the template controllers taking into account the template activate experiment. This is required as parsing and re-serializing blocks disrupts the render chain, in particular it breaks shortcodes in patterns and also render_block_core/pattern hooks, because the wrapping pattern was not there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contentOnly patterns: mark patterns as contentOnly by adding metadata.patternName to the root block

5 participants