WordPress 5.8 allows us to place blocks in widget areas. How can I register an ACF block with acf_register_block_type()
so that it is restricted to the widget screen? I can already restrict blocks to specific post types by setting the post_types
parameter – is there a similar solution for widgets?
Did you try to add category: ‘widgets’ during blog register?
@hellmute No, because I don’t want the block to be in the widget category, but to be restircted to placement inside the widget section of the theme (formerly known as sidebars), which is a new feature in WordPress 5.8 and totally unrelated to the block category *widget*.
@hellmute Interesting, thanks for pointing that out. I hope ACF implements this into its block API as soon as there’s a stable solution.
I’m also looking for a solution to this as I’ve created blocks that are only meant for use in the Header & Footer widget areas and want to restrict their use to only those. Unfortunately putting them into the widgets category doesn’t restrict them to at least the widgets page, it just puts them in that category.
Looking forward to this being available.
We’re using this code in the allowed_block_types function here: https://developer.wordpress.org/reference/hooks/allowed_block_types_all/
// Override array to only show widget specific blocks to widget page.
if ( $editor_context->name == 'core/edit-widgets' ) {
$allowed_block_types = array(
'acf/footerlinks',
'acf/footercta',
'acf/footergegevens',
'acf/footerlinksurl',
);
}