Hello.
With acf I was able to successfully integrate several own blocks into Gutenberg. So far everything has fit here – thanks to acf!
Now I wanted to clean up the WordPress backend in the Gutenberg editor and hide some blocks.
As far as I understood it correctly, here is the standard way via function.php and “allowed_block_types”. So I allow all blocks I define here. That works so far, but now also the acf blocks disappear, because I didn’t explicitly allow them!
Here is an excerpt:
function uniques_allowed_block_types( $allowed_blocks ) {
return array(
// Common blocks category
'core/paragraph',
'core/image',
'core/heading',
'core/gallery',
...
// 'core-embed/tumblr',
// 'core-embed/videopress',
// 'core-embed/wordpress-tv',
// 'core-embed/amazon-kindle',
// reusable blocks
'core/block',
);
}
add_filter( 'allowed_block_types', 'uniques_allowed_block_types' );
What do I have to do, or what is the correct statement in the array called, so that I can see my blocks in the Gutenberg editor?
best regards
After testing, the answer is acf/YOUR_BLOCK_NAME. You can see the names of all the blocks when you switch to the Gutenberg’s Code Editor – access it from the Gutenberg’s options tab…
This is what I’m using to disable core blocks, and WooCommerce blocks. The core blocks I want to use are at the bottom.
function remove_default_blocks($allowed_blocks){
// Get widget blocks and registered by plugins blocks
$registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
// Disable Widgets Blocks
unset($registered_blocks['core/calendar']);
unset($registered_blocks['core/legacy-widget']);
unset($registered_blocks['core/rss']);
unset($registered_blocks['core/search']);
unset($registered_blocks['core/tag-cloud']);
unset($registered_blocks['core/latest-comments']);
unset($registered_blocks['core/archives']);
unset($registered_blocks['core/categories']);
unset($registered_blocks['core/latest-posts']);
unset($registered_blocks['core/shortcode']);
// Disable WooCommerce Blocks
unset($registered_blocks['woocommerce/handpicked-products']);
unset($registered_blocks['woocommerce/product-best-sellers']);
unset($registered_blocks['woocommerce/product-category']);
unset($registered_blocks['woocommerce/product-new']);
unset($registered_blocks['woocommerce/product-on-sale']);
unset($registered_blocks['woocommerce/product-top-rated']);
unset($registered_blocks['woocommerce/products-by-attribute']);
unset($registered_blocks['woocommerce/featured-product']);
// Now $registered_blocks contains only blocks registered by plugins, but we need keys only
$registered_blocks = array_keys($registered_blocks);
// Merge allowed core blocks with plugins blocks
return array_merge(array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
), $registered_blocks);
}
add_filter('allowed_block_types', 'remove_default_blocks');
Just to add that even though my ACF block was registered with underscores in the name, these had to be replaced with hyphens in the allowed_block_types() function for it to work!
add_filter( 'allowed_block_types', 'custom_allowed_block_types' );
function custom_allowed_block_types( $allowed_blocks ) {
return array(
'acf/single-text-column',
'acf/text-image-block'
);
}
Hope this helps someone 🙂
The topic ‘acf Blocks and "allowed_block_types"’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.