Home › Forums › Gutenberg › ACF Blocks – Need stable id › Reply To: ACF Blocks – Need stable id
I can into the same problem with the suggested solution from ACF. But further research showed that only attributes set directly in the $block scope are reset. Setting it in $block[‘data’] makes it persistent
function mypre_add_anchor_to_blocks( $attributes ) {
error_log('attributes');
error_log( print_r( $attributes, true ) );
if( !isset($attributes['data']['customvalue']) || empty($attributes['data']['anchor']) ) {
$attributes['data']['customvalue'] = 'block-' . uniqid();
}
return $attributes;
}
add_filter('acf/pre_save_block', 'mypre_add_anchor_to_blocks');
Notice – on first save of the page you need to reload the admin page with the editor to make the block include the new attribute.
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.