-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make global styles available to all themes #34334
Conversation
They just differ on what data they have: 1. Without theme.json and no experimental-link-color support either: the stylesheet contains the core presets & styles. 2. Without theme.json but experimental-link-color support: the stylesheet contains the core and theme presets, plus the core styles if any. 3. With theme.json: the stylesheet contains the core and theme presets, plus the result of merging core & theme styles.
@youknowriad I'm seeing this piece of CSS in addition to the presets output for TwentyTwentyOne and TwentyTwenty. I presume this doesn't have to be enqueued unless there's a body {
--wp--style--block-gap: 24px;
}
.wp-site-blocks > * + * {
margin-top: var(--wp--style--block-gap);
margin-bottom: 0;
} |
ok, removed the block gap styles for TwentyTwentyOne and TwentyTwenty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases work for me as described.
ok, removed the block gap styles for TwentyTwentyOne and TwentyTwenty.
There may be a harmless edge case here:
- Activate a theme with a theme.json
- Make a post/page and add a block that inherits layout
- Switch to a theme without a theme.json
- Gutenberg will still generate alignment styles for those containers, but
--wp--style--block-gap
will be undefined.
@jffng That seems to happen in the transition from a theme with |
Why? and how could this be disabled? |
Hi Michael, the issue this fixes #34328 explains the rationale. Note that this won't add any additional CSS that is not already shipped by other means (block-editor, block-library). We're simply moving that CSS from the packages to the global stylesheet. |
Okay, I see. But in my frontend is added: <style id='global-styles-inline-css' type='text/css'>
/* ... */
--wp--preset--color--
/* ... */
</style> This is what I want to disable because it's useless for me and bloats my frontend output. |
Hey, that's how the global stylesheet works. These are used across all the color classes (color, background, border) and theme authors reported them as useful as well. We don't have plans to remove them or to add any option to do so automatically. |
Okay, I see the point. But is it not really possible, via hook, to remove not used presets like gradients, duotones, colors? I'm a frontend developer, I want to reduce code for faster loading. So why should I ship things, my theme and frontend never use? Yes it is usefull for theme authors, but not really for theme or frontend developers. |
Hey Michael, if the theme you're using does not define any presets, no classes and CSS custom properties will be enqueued. Is that enough for you? A different thing is that the presets defined by core will always be enqueued. The rationale for this can be discussed at #29568 It boils down to have stable colors available across themes for patterns. We also plan to expose them in the UI for users soon (see new color panel) #27473 (comment) |
$type = 'all'; | ||
if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { | ||
$type = 'presets'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this $type
check be part of gutenberg_experimental_global_styles_get_stylesheet
directly? Meaning if there's no theme.json just pint the presets otherwise print everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be inside this function that way it works consistently regardless of the caller.
gutenberg/lib/class-wp-theme-json-gutenberg.php
Line 1072 in a59775a
public function get_stylesheet( $type = 'all' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 not sure how to do it. There're other calls below where, in the same code path, where want to build two different stylesheets (pseudocode):
$block_styles = gutenberg_experimental_global_styles_get_stylesheet( $tree, 'block_styles' );
$css_variables = gutenberg_experimental_global_styles_get_stylesheet( $tree 'css_variables' );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, themes without theme.json shouldn't return just the "presets" like always. It shouldn't be the responsibility of the caller to switch the "type" depending on the theme, the caller just asks for the stylesheet and returning the right styles should be internal logic.
Hi again André, yes I understand:
But such people could also add / merge the system colors via theme settings on their own (that I've done before).
That's right but my theme uses presets, custom properties and - of course - lot of classes:
Not really. The wp-presets - specially the gradients - should not be merged, if theme has no gradients or set to false. But I found a solution (in hope not having other side effects): add_action('wp_enqueue_scripts', function() {
wp_dequeue_style('global-styles');
// ... code for to enqueue my own 'global-inline-css'
});
// or as an alternative:
//remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well in my testing (as advertised).
Maybe we could abstract away the "type" check as suggested above.
@mkkeck Note that the core classes and properties may be used by patterns and will be exposed to users through the color panel well. I'd think it's fine to dequeue the global stylesheet and do your own enqueueing if you don't personally mind about that. I'd recommend checking regularly in the Gutenberg release announces for changes in that area to make sure changes still work for you, though, as removing the core CSS is unexpected and not something we can cover for. |
Follow-up to remove CSS from the base-styles and block-library packages at #34510 |
DevnoteTo review/clarify/check when time comes to publish it. We've made some changes to the stylesheets enqueued by default such as:
:root {
--wp--preset--{preset-type}--{preset-slug}: <core-value>;
--wp--preset--color--pale-pink: #f78da7;
--wp--preset--font-size--huge: 42px;
// ...
}
.has-<slug>-<preset-type> { ... }
.has-pale-pink-color { color: var(--wp--preset--color--pale-pink) !important; }
.has-huge-font-size { color: var(--wp--preset--font-size--huge) !important; } Themes that use the theme.json can set these values in that file. Themes that don't, can set the CSS Custom Property in their stylesheet with something like: :root {
--wp--preset--font-size--huge: <theme-value>;
} |
Can we please remove the "!important" flag within the preset classes? Or at least add a filter that enables us to do so? See #34575 (comment) I really do not want to start using the !important flag all over my theme to override things. My frontend theme is also CMS agnostic, so it's a pain to code more and more exceptions for WordPress. |
More and more the Gutenberg project dictates theme and frontend developers how to use, write and code their themes to work with Gutenberg. General, I like the Gutenberg Editor, but sometimes there's project philosophy, which is not acceptable:
That things have nothing to do with "CODE IS POETRY". New features are really welcome, but these features should always have an opt-in or opt-out before rolling out to the WordPress core. All these features should also apply filters and actions, which enables patching. It is really bad to leave users, after minor upgrading their WordPress, with broken themes or plugins (and as result broken websites). I must say, before FSE, there were less such issues. But some core developers here, I think, won't here them. WordPress and Gutenberg should be tools to help end users to build pages and write content, not more and not less. |
This introduced a bug that I'm fixing at #34955 |
I've updated a bit the devnote for this. |
Prepared #35424 to enqueue preset styles in the editor as well. |
Fixes #34328
This PR makes global styles available to all themes.
How to test
Activate TT1-blocks: a theme with
theme.json
support. Visit the front end. Check the content ofglobal-styles-inline-css
is:Activate the TwentyTwentyOne theme: a theme without theme.json but with
experimental-link-color
support. Visit the front end. Check the content ofglobal-styles-inline-css
is:Activate the TwentyTwenty theme: a theme without theme.json and no
experimental-link-color
support. Visit the front end. Check the content ofglobal-styles-inline-css
is:Follow-ups
Remove the styles included here from the
block-library
package.