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',
...