#55148 closed defect (bug) (fixed)
In block themes, styles should load in the head
Reported by: | oandregal | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 5.9.1 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | Script Loader | Keywords: | has-patch |
Focuses: | Cc: |
Description
WordPress 5.8 introduced some logic to load some styles in the bottom of the body for classic themes that opted-in into loading block assets separately. For classic themes that didn't opt-in and block themes, the styles should be loaded in the head.
Specifically, in https://core.trac.wordpress.org/ticket/53494 global styles were set to do that. However, at some point during the WordPress 5.9 cycle, a regression was introduced that made block themes to have the global styles in the body.
Similarly, block styles generated by WordPress dynamically (layout and elements) should have been loaded following the same logic. Instead, these are always loaded in the body.
Change History (22)
This ticket was mentioned in PR #2303 on WordPress/wordpress-develop by oandregal.
3 years ago
#2
Trac ticket https://core.trac.wordpress.org/ticket/55148
Backports https://github.com/WordPress/gutenberg/pull/38745
In the linked trac ticket we added some logic to load the global stylesheet in the bottom of <body>
for classic themes that opted-in into loading individual block styles instead of a single stylesheet for them all. At the time, block themes always loaded the global stylesheet in the <head>
.
When block themes landed in core during the WordPress 5.9 this logic wasn't updated to consider them, hence the global stylesheet loaded in the <body>
for them. This PR fixes this.
## How to test
- Block theme: load a site using TwentyTwentyTwo and verify that the
global-styles-inline-css
embedded stylesheet is loaded in the<head>
. - Classic theme that doesn't opt in into
should_load_separate_core_block_assets
: load a site using TwentyTwenty and verify that theglobal-styles-inline-css
embedded stylesheet is loaded in the<head>
. - Classic theme that opts-in into
should_load_separate_core_block_assets
:- Use TwentyTwenty.
- Add
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
to itsfunctions.php
. - Load the site and verify that the
global-styles-inline-css
is loaded at the bottom of the<body>
.
#4
@
3 years ago
I think the problem is not only in global styles. Also, inline styles for container and elements are loaded in body
This is set to place style tags wp_footer in files
wp-includes/block-supports/elements.php
wp-includes/block-supports/layouts.php
When, I changed to wp_head - everything starts to work smoothly. Can we load inline styles in head for block themes?
#5
@
3 years ago
- Keywords commit added
- Owner set to audrasjb
- Status changed from new to assigned
The proposed PR was reviewed by @aristath.
Self assigning for commit.
3 years ago
#8
Committed in https://core.trac.wordpress.org/changeset/52738
#9
@
3 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for backport
This ticket was mentioned in PR #2323 on WordPress/wordpress-develop by oandregal.
3 years ago
#11
Part of https://core.trac.wordpress.org/ticket/55148#comment:10
Backports https://github.com/WordPress/gutenberg/pull/38750
The dynamic block styles for layout and elements should be loaded in the <head>
for block themes. While that should also be the case for classic themes, the current mechanism we use (render_block
) does not allow us to do that, hence, this PR doesn't change anything for them and will be loaded the <body>
.
## How to test
Block theme in WordPress 5.9:
- Use TwentyTwentyTwo and load the front end.
- Verify the embedded styles for elements (
.wp-elements-UUID ...
) and layout (.wp-container-UUUID ...
) are loaded in the<head>
.
Classic theme in WordPress 5.9:
- Use TwentyTwenty and load the front end.
- Verify the embedded styles for elements (
.wp-elements-UUID ...
) and layout (.wp-container-UUUID ...
) are loaded in the<body>
.
#12
@
3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
For this ticket to be fully fixed, we also need to enqueue the block support styles (layout, elements) in the head for block themes. I've prepared a PR for that at https://github.com/WordPress/wordpress-develop/pull/2323
(Also to be backported to 5.9.1)
#15
@
3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopenning for backport to 5.9.1.
oandregal commented on PR #2323:
3 years ago
#16
@swissspidy @hellofromtonya I see this had already been approved&commited at https://core.trac.wordpress.org/changeset/52741
Is there anyone with commit access that can do those changes directly? I also can prepare a follow-up if it's convenient for people.
hellofromtonya commented on PR #2323:
3 years ago
#17
@jorgefilipecosta is preparing a follow-up commit https://wordpress.slack.com/archives/C02RQBWTW/p1645035406929929
This ticket was mentioned in PR #2328 on WordPress/wordpress-develop by jorgefilipecosta.
3 years ago
#18
Applies feedback to https://github.com/WordPress/wordpress-develop/pull/2323
This commit applies feedback given to commit 52741. It changes the new function name, the file where it is located, and improves its documentation and marks.
Follow-up to [52741].
Props hellofromtonya, swissspidy, oandregal.
See #55148.
I've got a PR to fix the global styles https://github.com/WordPress/wordpress-develop/pull/2303