Make WordPress Core

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: edent's profile edent 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

## Summary

  • Fixes a regression where global-styles-inline-css could not be removed in classic themes after WordPress 6.9/7.0.
  • Since global styles are now generated in wp_footer and hoisted into <head>, older opt-out patterns (remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ) and wp_dequeue_style( 'global-styles' ) during wp_enqueue_scripts) no longer prevented the inline CSS from appearing.
  • This change detects theme/plugin opt-outs and skips generating/hoisting global styles when requested.

## What changed

In wp_enqueue_global_styles() for classic themes with on-demand block assets:

  1. Queue the global-styles handle during wp_enqueue_scripts so it can be dequeued before footer processing.
  2. Run a deferred check at the end of wp_enqueue_scripts to detect dequeue/remove opt-outs.
  3. Skip footer global styles generation when an opt-out is detected.

## Why this is a valid bug

Before 6.9/7.0, dequeuing or removing the wp_enqueue_scripts callback was sufficient to prevent global-styles-inline-css. With footer-based generation + hoisting, those calls became ineffective, breaking existing classic theme setups that intentionally disable global styles.

## Test plan

  • [x] npm run test:php -- --filter test_wp_hoist_late_printed_styles (15/15 passing)
  • [x] PHPCS on src/wp-includes/script-loader.php and tests/phpunit/tests/template.php
  • [ ] On a classic theme (no blocks), confirm global-styles-inline-css appears by default
  • [ ] Confirm wp_dequeue_style( 'global-styles' ) on wp_enqueue_scripts removes it
  • [ ] Confirm remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ) removes it
  • [ ] Confirm block themes and normal global styles loading are unaffected
Note: See TracTickets for help on using tickets.