-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed as not planned
Closed as not planned
Copy link
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
I tried to style a new custom block style in the theme.json via block style the variations properties (Snippet 2 below)
The block style is registered via register_block_style (Snippet 1 below).
Turns out Gutenberg doesn't generate the CSS for that block style, both in the block editor and front website.
This is the bug.
If I add a new block style via register_block_type_args filter (Snippet 3 below), it works perfectly.
Step-by-step reproduction instructions
How to replicate the bug:
- Add the Snippet 1 (below) into the
functions.php. This will register a new block style for thecore/headingblock viaregister_block_style()function. - Add the Snippet 2 (below) into the
theme.json. This will give red and yellow colored for thecore/headingblock with the newtitleblock style. - Go to block editor and add a
core/headingblock into the content. - Choose the
Titleblock style. - The heading block is not in red and yellow colored.
- If we check the page source, there is no generated CSS for
.is-style-titlein thecore/headingblock inline CSS.
Adding a new block style via register_block_type_args filter:
- Add the Snippet 3 (below) into the
functions.php. This will register a new block style for thecore/headingblock viaregister_block_type_argsfilter. - Reload the page that contains the
core/headingblock withTitleblock style. - The heading block is in red and yellow colored.
- If we check the page source, there is a new generated CSS for
.is-style-titlein thecore/headingblock inline CSS.
Screenshots, screen recording, code snippet
Snippet 1 (functions.php):
<?php
register_block_style(
'core/heading',
array(
'name' => 'title',
'label' => esc_html__( 'Title', 'textdomain' ),
)
);
Snippet 2 (theme.json):
{
...
"styles": {
"blocks": {
"core/heading": {
"variations": {
"title": {
"color": {
"background": "yellow",
"text": "red"
}
}
}
}
}
}
}
Snippet 3 (functions.php):
<?php
add_filter(
'register_block_type_args',
function( $args, $block_type ) {
if ( 'core/heading' === $block_type ) {
$args['styles'][] = array(
'name' => 'title',
'label' => esc_html__( 'Title', 'textdomain' ),
);
}
return $args;
},
10,
2
);
Environment info
- WordPress 6.4.3
- Gutenberg 17.8.2
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended