Home › Forums › General Issues › ACF Pro 6 Block IDs as Attribute Not Working › Reply To: ACF Pro 6 Block IDs as Attribute Not Working
I’m not sure if you need the ID to always be the same or just unique, but if you are simply after an ID value in the template, maybe you can use something I made for a somewhat similar case. I just needed an ID for the template, without saving all the blocks again.
I faced the same issues and the suggested solution didn’t really work as expected. Instead I used a WP filter that doesn’t get changed by ACF
I used it to check for old align_content
and align_text
that are also changed in ACF 6.x, and at the same time I set the ID – if they aren’t already available.
None of the attributes are actually saved with the block. They are dynamic and meant to be bridge old attributes that ACF removes and be available in the template.
function acf_legacy_attributes_missing( $parsed_block, $source_block, $parent_block ) {
$parsed_block['attrs']['align_content_acf_legacy'] = ( !empty( $parsed_block['attrs']['align_content'] ) ? $parsed_block['attrs']['align_content'] : '' );
$parsed_block['attrs']['align_text_acf_legacy'] = ( !empty( $parsed_block['attrs']['align_text'] ) ? $parsed_block['attrs']['align_text'] : '' );
$parsed_block['attrs']['id'] = ( !empty( $parsed_block['attrs']['id'] ) ? $parsed_block['attrs']['id'] : 'block_id_' . uniqid() );
return $parsed_block;
}
add_filter( "render_block_data", "acf_legacy_attributes_missing", 10, 3 );
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.