Opened 5 hours ago
Last modified 4 hours ago
#65336 new defect (bug)
global-styles-inline-css cannot be removed since 7.0
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 7.0 |
| Component: | General | Keywords: | has-patch has-unit-tests |
| Focuses: | css | Cc: |
Description
I recently upgraded to 7.0. This has caused global-styles-inline-css to be forcibly injected into my blogs's <head>. This breaks some of my styles.
Previously, I was able to put the following in my theme to remove global-styles-inline-css - but this no longer works.
<?php add_action( "wp_enqueue_scripts", "remove_global_styles" ); function remove_global_styles() { wp_dequeue_style( "global-styles-inline" ); } remove_action( "wp_enqueue_scripts", "wp_enqueue_global_styles" );
Neither of those work. I do not use blocks. I have removed Gutenberg.
<?php function remove_wp_block_library_css():void { wp_dequeue_style( "wp-block-library" ); wp_dequeue_style( "wp-block-library-theme" ); wp_dequeue_style( "wp-components" ); } add_action( "wp_enqueue_scripts", "remove_wp_block_library_css", 100 );
This appears to be a regression. Previously it was possible to remove the unwanted and unnecessary CSS. Now it is not.
Change History (1)
This ticket was mentioned in PR #11961 on WordPress/wordpress-develop by @khokansardar.
4 hours ago
#1
- Keywords has-patch has-unit-tests added
Note: See
TracTickets for help on using
tickets.
## Summary
global-styles-inline-csscould not be removed in classic themes after WordPress 6.9/7.0.wp_footerand hoisted into<head>, older opt-out patterns (remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' )andwp_dequeue_style( 'global-styles' )duringwp_enqueue_scripts) no longer prevented the inline CSS from appearing.## What changed
In
wp_enqueue_global_styles()for classic themes with on-demand block assets:global-styleshandle duringwp_enqueue_scriptsso it can be dequeued before footer processing.wp_enqueue_scriptsto detect dequeue/remove opt-outs.## Why this is a valid bug
Before 6.9/7.0, dequeuing or removing the
wp_enqueue_scriptscallback was sufficient to preventglobal-styles-inline-css. With footer-based generation + hoisting, those calls became ineffective, breaking existing classic theme setups that intentionally disable global styles.## Test plan
npm run test:php -- --filter test_wp_hoist_late_printed_styles(15/15 passing)src/wp-includes/script-loader.phpandtests/phpunit/tests/template.phpglobal-styles-inline-cssappears by defaultwp_dequeue_style( 'global-styles' )onwp_enqueue_scriptsremoves itremove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' )removes it