Hi there,
I’m struggeling in getting the anchor field to a new ACF-Block, with acf_register_block_type.
According to this page it should work: https://www.advancedcustomfields.com/resources/blocks/
I tried: supports
'anchor' => true
'id' => true
.
But it always just show me the class-name, not any anchor or id field.
Does anybody has an Idea what I’m making wrong?
Hello everyone,
I am also confused with this option. Is it available somewhere? Where to set that 'anchor'
for a block?
I’ve got this answer from the ACF-Support.
Thank you for your email.
I hate to be the bearer of bad news but the acf_register_block_type() function currently does not support the ‘anchor’ property. You can have a look at its documentation here https://www.advancedcustomfields.com/resources/acf_register_block_type/.
I hope this helps and kindly let me know how this goes :).
My teammate calims that it works, just have to add 'supports' => array('anchor')
while registering the block. Update the ACF, have a try and let me know
I just tried it with ACF 5.9.4.
Unfortunately without success. Does it work for you?
@freddyfy @sabrinahill
You need to set anchor to true, then click on the block in the panel admin and on the right side Block -> Advanced there is an anchor setting.
'supports' => array( 'anchor' => true )
@kopiczko-sebastian can confirm it works perfectly. Thanks for this!
acf_register_block_type(
array(
'name' => 'countdown',
'title' => __('Countdown', TEXTDOMAIN),
'description' => __('A custom Countdown block.', TEXTDOMAIN),
'render_template' => 'template-parts/blocks/countdown.php',
'category' => 'my-custom-blocks',
'icon' => 'calendar-alt',
'keywords' => array( 'countdown', 'date', 'time' ),
'supports' => array( 'anchor' => true )
)
);
If it “works”, why ‘anchor’ doesn’t appears into parameters list of documentation?
https://www.advancedcustomfields.com/resources/acf_register_block_type/#parameters
Anchor IS indirectly mentioned in the documentation: the documentation states:
supports
(Array) (Optional) An array of features to support. All properties from the JavaScript block supports documentation may be used. The following options are supported:
If you read the linked documentation at https://developer.wordpress.org/block-editor/developers/block-api/block-supports/ — anchor is the first parameter on the list.
What’s the best way to register the anchor support to an already existing ACF field group? I don’t need a custom block, I only need the anchor option to create a sub-menu on this page for easy navigation. If a custom block is the only way then I understand but wanted to explore other options before diving into creating one.
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.