admin管理员组文章数量:1326287
For a WordPress theme I deregister a few blocks for Gutenberg (in fact, I only register the ones I need).
For this, I use a filter:
add_filter( 'allowed_block_types', 'amb_allowed_block_types' );
This filter hooks into a function like this:
function amb_allowed_block_types( $allowed_blocks ) {
return [
'core/paragraph',
'core/image',
'core/heading',
'core/gallery',
...
This works nice. But I don't want to use this filter if it is being used on a WP theme that doesn't have Gutenberg enabled. How can I make sure that this filter is only being used on Gutenberg sites?
Many thanks!
For a WordPress theme I deregister a few blocks for Gutenberg (in fact, I only register the ones I need).
For this, I use a filter:
add_filter( 'allowed_block_types', 'amb_allowed_block_types' );
This filter hooks into a function like this:
function amb_allowed_block_types( $allowed_blocks ) {
return [
'core/paragraph',
'core/image',
'core/heading',
'core/gallery',
...
This works nice. But I don't want to use this filter if it is being used on a WP theme that doesn't have Gutenberg enabled. How can I make sure that this filter is only being used on Gutenberg sites?
Many thanks!
Share Improve this question asked Aug 5, 2020 at 13:50 ralphjsmitralphjsmit 4026 silver badges23 bronze badges 2- 1 That filter won't do anything if they don't have the Block Editor enabled, so you shouldn't need to do anything additional. – WebElaine Commented Aug 5, 2020 at 14:11
- Hi @WebElaine thank you! – ralphjsmit Commented Aug 5, 2020 at 17:58
1 Answer
Reset to default 0You can check if the current theme supports Gutenberg blocks inside your function
function amb_allowed_block_types( $allowed_blocks ) {
if(! current_theme_supports('wp-block-styles') ){
return $allowed_blocks;
}
return [
'core/paragraph',
'core/image',
'core/heading',
'core/gallery',
...
本文标签: block editorHow do I check if I can use the allowedblocktypes filter
版权声明:本文标题:block editor - How do I check if I can use the allowed_block_types filter? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742209744a2433488.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论