admin管理员组文章数量:1122846
I'm having huge difficulties with the forced styling bundled in WP (using hybrid themes):
body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) {
max-width: var(--wp--style--global--content-size);
margin-left: auto !important;
margin-right: auto !important;
}
Because my themes uses its own width settings and whenever I add a group block the code above gets added (which is pure evil). I can't really use add_theme_support( 'disable-layout-styles' );
because then things like justification on buttons block won't work (in admin/editor).
I added
"layout": {
"contentSize": "100%",
"wideSize": "100%"
},
in my theme.json
which sort of works but forces the users to manually set the blockwidth to fullwidth on each block.
My latest idea is to add the class "alignfull" to all group blocks programmatically instead. I use this snippet with success but render_block is frontend only (what I know).
add_filter( 'render_block', 'add_class_to_group_block', 10, 2 );
/**
* Add .alignfull class on group blocks to get rid of the horrible !important margins on non-aligned blocks
*/
function add_class_to_group_block( $block_content, $block ) {
if ( 'core/group' === $block['blockName'] ) {
$block_content = new WP_HTML_Tag_Processor( $block_content );
$block_content->next_tag();
$block_content->add_class( 'alignfull' );
$block_content->get_updated_html();
}
return $block_content;
}
Is there anything similar to render_block
for admin/editor usage? Or can I solve this dilemma in another way?
本文标签: cssHow to add a class to a core block in both admin editor and frontend
版权声明:本文标题:css - How to add a class to a core block in both admin editor and frontend? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307984a1933502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论