[wp-trac] [WordPress Trac] #54975: Allow filtering global styles

WordPress Trac noreply at wordpress.org
Fri Jan 28 14:45:57 UTC 2022


#54975: Allow filtering global styles
--------------------------+-----------------------------
 Reporter:  webmandesign  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.9
 Severity:  normal        |   Keywords:
  Focuses:  css           |
--------------------------+-----------------------------
 Due to using `!important` and possibly high selector specificity in CSS
 declarations in global styles code produced by WordPress 5.9, many themes
 supporting Gutenberg editor (but not block/FSE themes)
 [https://github.com/WordPress/gutenberg/issues/38252#issuecomment-1023345698
 experience issues] with WordPress overriding their custom font sizes and
 color palettes ([https://developer.wordpress.org/block-editor/how-to-
 guides/themes/theme-support/ registered via `add_theme_support()`]).

 It would be great if WordPress allowed at least filtering global styles
 code (produced by [https://github.com/WordPress/WordPress/blob/5.9/wp-
 includes/global-styles-and-settings.php#L88 `wp_get_global_stylesheet()`])
 with a hook, such as: changing
 [https://github.com/WordPress/WordPress/blob/5.9/wp-includes/global-
 styles-and-settings.php#L133 `return $stylesheet;`] in
 `wp_get_global_stylesheet()` to:

 {{{#!php
 /**
  * Filters the global CSS styles code.
  *
  * @since 5.9.1
  *
  * @param string $stylesheet CSS styles code.
  * @param array  $types      Types of styles to load.
  * @param array  $origins    A list of origins to include.
  */
 return apply_filters( 'global_styles', $stylesheet, $types, $origins );
 }}}

 That way WordPress can keep its global styles intact (even with
 `!important` if that's really the best way to provide the styles...) for
 block/FSE themes and Gutenberg editor themes can adapt the global styles
 by using this filter if needed.

 (Block/FSE themes and themes that do not add support for Gutenberg editor
 do not seem to be affected.)

 ----

 More info can be found in
 https://github.com/WordPress/gutenberg/issues/38252#issuecomment-1023345698
 and related comments.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54975>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list