Make WordPress Core


Ignore:
Timestamp:
07/13/2026 09:41:34 AM (9 days ago)
Author:
wildworks
Message:

Block Supports: Ensure custom CSS prints after block library styles.

The wp-block-custom-css handle depended only on global-styles, which pulled global-styles forward in the print order, ahead of wp-block-library. Block library default styles then printed last and overrode global styles.

Declare wp-block-library before global-styles in the handle's dependency array so wp-block-library prints first and global-styles keeps winning the cascade.

Developed in: https://github.com/WordPress/wordpress-develop/pull/12461

Follow-up to [61678], [62656].

Props ramonopoly, westonruter, wildworks.
Fixes #65602.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/custom-css.php

    r62656 r62706  
    7070        if ( ! empty( $processed_css ) ) {
    7171                /**
    72                  * Skip CSS that has already been added. Blocks with identical attributes
    73                  * share the same class name and processed CSS via {@see wp_unique_id_from_values()},
    74                  * so the same style would otherwise be enqueued more than once (e.g. inside
    75                  * a Query Loop or when blocks share identical custom CSS).
     72                 * Reuse one handle so identical custom CSS is enqueued only once via
     73                 * {@see wp_unique_id_from_values()}. Explicitly declare the `wp-block-library`
     74                 * dependency so `global-styles` is guaranteed to print after it, preventing
     75                 * block default styles from unintentionally overriding global styles.
    7676                 */
    7777                $handle = 'wp-block-custom-css';
    7878                if ( ! wp_style_is( $handle, 'registered' ) ) {
    79                         wp_register_style( $handle, false, array( 'global-styles' ) );
     79                        wp_register_style( $handle, false, array( 'wp-block-library', 'global-styles' ) );
    8080                }
    8181                $after_styles = wp_styles()->get_data( $handle, 'after' );
Note: See TracChangeset for help on using the changeset viewer.