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 );