-
Notifications
You must be signed in to change notification settings - Fork 4.6k
contentOnly patterns: mark patterns as contentOnly by adding metadata.patternName to the root block #72988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contentOnly patterns: mark patterns as contentOnly by adding metadata.patternName to the root block #72988
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
lib/compat/wordpress-6.9/class-gutenberg-rest-static-templates-controller.php
Show resolved
Hide resolved
lib/compat/wordpress-7.0/class-gutenberg-rest-registered-templates-controller.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-7.0/class-gutenberg-rest-templates-controller-7-0.php
Outdated
Show resolved
Hide resolved
lib/compat/wordpress-6.9/class-gutenberg-rest-old-templates-controller.php
Show resolved
Hide resolved
|
Flaky tests detected in e76d2a4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19220458596
|
andrewserong
left a comment
There was a problem hiding this 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-404pattern, 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-searchpattern 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!
lib/compat/wordpress-7.0/class-gutenberg-rest-templates-controller-7-0.php
Outdated
Show resolved
Hide resolved
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! |
|
Hol up! I'll refactor this once the following is in: |
Might be a good one: Uses: I'll test when I come back to rebase/refactor this on top of #73025 |
There was a discussion somewhere (can't find it now) about being able to mark some patterns so that we skip applying the |
Where's the best place to do this? Assuming the frontend, where there's already logic to detect content only blocks inside a section? |
|
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 |
…ts to ensure controller returns expected content.
8409ed1 to
91f2b5a
Compare
|
|
Okay this is ready for a final test after the migration to filters. Thanks for the help so far, folks! |
There was a problem hiding this 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.
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 I don't think we need to detect content only blocks inside a pattern ... we'd skip adding |
…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.


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-templatesendpoint.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_blocksfunction to include metadata for single-root patterns, allowing the pattern name and title to be stored in the block attributes. The metadata contains thepatternNameandnameattributes.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-experimentsto enable thecontentOnly: Make patterns contentOnly by default upon insertionexperiment.I'm using TT4 to test.
Head over to
/wp-admin/site-editor.php?p=%2FtemplateIn the browser network console, you can check the response of
/wp/v2/registered-templatesto see if the template content contains pattern metadata (search formetadata)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