Skip to content
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

Opt to register styles in standard way #785

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Conversation

westonruter
Copy link
Owner

Fixes #286.

By registering styles for the block in the traditional way, we can be guaranteed that the style will be printed to the page. There are scenarios (see #286) in which a block can be rendered and yet not printed, and this can prevent the inlined styles from being served. Styles were originally inlined in this way in order to prevent serving them when they weren't needed. Nevertheless, block themes now by default only print styles for blocks which are actually rendered on the page. And yet, classic themes do still print all styles for all registered blocks in the head unconditionally. In order to retain that conditional style printing, you can add the following plugin code:

add_filter( 'should_load_separate_core_block_assets', '__return_true' );

For classic themes, this has the effect of printing block styles in the footer since only at this point does WordPress know which blocks have been rendered. The downside here is that there may be a flash of unstyled content and critical styles may not be loaded soon enough.

@westonruter westonruter merged commit dd87d7b into develop Nov 21, 2023
2 checks passed
@westonruter westonruter deleted the update/style-handling branch November 21, 2023 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlighting stopped working
1 participant