-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Adding duotone support to core block via filter does not enqueue front-end duotone styles/SVG #62852
Comments
I tried to provide support for |
As I understand it, the duotone styles on the frontend are generated server-side, i.e. by PHP. function custom_register_block_type_args( $args, $block_type ) {
if ( 'core/media-text' !== $block_type ) {
return $args;
}
if ( ! isset( $args['supports'] ) ) {
$args['supports'] = array();
}
if ( ! isset( $args['selectors'] ) ) {
$args['selectors'] = array();
}
$args['supports'] = array_merge(
$args['supports'],
array(
'filter' => array(
'duotone' => true,
),
)
);
$args['selectors'] = array_merge(
$args['selectors'],
array(
'filter' => array(
'duotone' => '.wp-block-media-text .wp-block-media-text__media',
),
)
);
return $args;
}
add_filter( 'register_block_type_args', 'custom_register_block_type_args', 10, 2 ); |
@t-hamano, Thank you, it works! |
@t-hamano Thank you for this! That is a clear answer and makes total sense. |
Just noting for completeness that you can also achieve the same result using the function example_add_duotone_to_media_text_blocks( $metadata ) {
// Only apply the filter to Media & Text blocks.
if ( ! isset( $metadata['name'] ) || 'core/media-text' !== $metadata['name'] ) {
return $metadata;
}
if ( ! isset( $metadata['supports'] ) ) {
$metadata['supports'] = array();
}
if ( ! isset( $metadata['selectors'] ) ) {
$metadata['selectors'] = array();
}
$metadata['supports'] = array_merge(
$metadata['supports'],
array(
'filter' => array(
'duotone' => true,
),
)
);
$metadata['selectors'] = array_merge(
$metadata['selectors'],
array(
'filter' => array(
'duotone' => '.wp-block-media-text .wp-block-media-text__media',
),
)
);
return $metadata;
}
add_filter( 'block_type_metadata', 'example_add_duotone_to_media_text_blocks' ); |
@ndiego Thanks for including that! Would you say there is a benefit to |
Description
Because of #32972 I'm adding Duotone to the Media & Text block for a client project. I have it working in the editor by filtering
blocks.registerBlockType
to setsupports.filter.duotone
true
. This works as expected in the editor, including for custom duotones.However, on the front-end, I cannot get it to work. My expectation is that if a block supports duotone filters, then it should trigger the required front-end styles.
I have tried both the deprecated
wp_render_duotone_support()
andWP_Duotone::render_duotone_support()
in arender_block
filter, but neither seems to output the SVGs and styles needed to render the filter. Although the deprecation message forwp_render_duotone_support()
references theWP_Duotone::render_duotone_support()
, it doesn't seem like a simple straight replacement.This is closely related to #53662, but feels different. I do wonder if they could both be solved together.
Step-by-step reproduction instructions
Here is my
index.js
compiled via@wordpress/scripts
that adds duotone support to the Media & Text block which works as expected in the editor.Screenshots, screen recording, code snippet
No response
Environment info
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
The text was updated successfully, but these errors were encountered: