Support

Account

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