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?
@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*.
@herrschuessler There is an ongoing discussion about this on github:
https://github.com/WordPress/gutenberg/issues/28517
https://github.com/WordPress/gutenberg/issues/33238#issuecomment-875261550
@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',
);
}
You must be logged in to reply to this topic.
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.