Home › Forums › General Issues › ACF Pro 6 Block IDs as Attribute Not Working › Reply To: ACF Pro 6 Block IDs as Attribute Not Working
It just dawned on me that the whole issue might really be related to ACF filtering attributes that aren’t defined in the group and instead of going through the hoops of my function above, you could achieve the same with the ACF suggested function you already tried – just by placing the value in ['data]
sub-node. Like this
function mypre_add_anchor_to_blocks( $attributes ) {
error_log('attributes');
error_log( print_r( $attributes, true ) );
if( !isset($attributes['data']['anchor']) || empty($attributes['data']['anchor']) ) {
$attributes['data']['anchor'] = 'block-' . uniqid();
}
return $attributes;
}
add_filter('acf/pre_save_block', 'mypre_add_anchor_to_blocks');
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.