afb/output

Description

This filter allows you to modify the final HTML output of an ACF field block after all formatting, styling, and HTML structure has been generated. This is the last hook in the rendering pipeline, giving you complete control over the final output that will be displayed on the front end.

Parameters

apply_filters( 'afb/output', $output, $field, $attr );
$output

(string)

The complete HTML output for the field block, including all tags and formatted content

$field

(array)

Complete field configuration array containing type, name, key, and other ACF field settings

$attr

(array)

Block attributes array containing block-specific settings

Modifiers

afb/output Applies to all fields.
afb/output/type={$type} Applies to all fields of a specific type.
afb/output/name={$name} Applies to all fields of a specific name.
afb/output/key={$key} Applies to all fields of a specific key.

Example

// Add a custom data attribute to the output
add_filter( 'afb/output', function( $output, $field, $attr ) {
    // Example: Add a custom data attribute
    if ( 'my_special_field' === $field['name'] ) {
        $output = str_replace( '<p ', '<p data-custom-field="true" ', $output );
    }
    return $output;
}, 10, 3 );

// Wrap output in a custom container
add_filter( 'afb/output', function( $output, $field, $attr ) {
    if ( 'text' === $field['type'] ) {
        return sprintf( '<div class="custom-text-wrapper">%s</div>', $output );
    }
    return $output;
}, 10, 3 );Code language: PHP (php)