Description
Filters the block attributes before they are used to render ACF field blocks. This hook allows developers to modify block attributes programmatically, enabling dynamic customization of block behavior, styling, and content presentation.
Parameters
apply_filters( 'afb/attributes', $attr, $field );
$attr
(array)
The block attributes array containing all block settings
$field
(array)
The ACF field array containing field configuration, key, name, type, and value
Modifiers
afb/attributes
|
Applies to all fields.
|
afb/attributes/type={$type}
|
Applies to all fields of a specific type.
|
afb/attributes/name={$name}
|
Applies to all fields of a specific name.
|
afb/attributes/key={$key}
|
Applies to all fields of a specific key.
|
Example
add_filter( 'afb/attributes/type=textarea', 'modify_textarea_attributes', 10, 2 );
function modify_textarea_attributes( $attr, $field ) {
$attr['tag'] = 'div';
$attr['style']['lineHeight'] = '1.8';
return $attr;
}Code language: PHP (php)