FSE: Custom blocks elements theme.json
-
I have developed a custom block. For the sake of this post, let’s reference it as
my-plugin/block. I have a.wp-element-captionelement within it which I would like to be able to style using the managed stylestheme.jsonlike:{ "version": 2, "styles": { "blocks": { "my-plugin/block": { "elements": { "caption": { "typography": "my-font" } } } } } }However, after debugging, it seems like the code in wp_add_global_styles_for_blocks() only accounts for core blocks:
// The likes of block element styles from theme.json do not have $metadata['name'] set. if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) { $result = array_values( array_filter( $metadata['path'], function ( $item ) { if ( strpos( $item, 'core/' ) !== false ) { return true; } return false; } ) ); if ( isset( $result[0] ) ) { if ( str_starts_with( $result[0], 'core/' ) ) { $block_name = str_replace( 'core/', '', $result[0] ); $stylesheet_handle = 'wp-block-' . $block_name; } wp_add_inline_style( $stylesheet_handle, $block_css ); } }Notice the
strpos( $item, 'core/' ) !== falseline. Thus, styling elements intheme.jsonseems like it is unavailable for custom-authored blocks. Could anyone confirm this or is there some sort of flag or otherwise that I am missing?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘FSE: Custom blocks elements theme.json’ is closed to new replies.