acf_render_field_label()ACF 5.6.3

acf_render_field_label

Renders the field's label.

No Hooks.

Returns

null. Nothing (null).

Usage

acf_render_field_label( $field );
$field(array) (required)
The field array.

Changelog

Since 5.6.3 Introduced.

acf_render_field_label() code ACF 6.8.8

function acf_render_field_label( $field ) {

	// Get label.
	$label = acf_get_field_label( $field );

	// Output label.
	if ( $label ) {
		// For multi-choice fields (radio, checkbox, taxonomy, button_group), don't use 'for' attribute but add ID for aria-labelledby
		if ( in_array( $field['type'], array( 'radio', 'checkbox', 'taxonomy', 'button_group' ), true ) && $field['id'] ) {
			echo '<label id="' . esc_attr( $field['id'] ) . '-label">' . acf_esc_html( $label ) . '</label>';
		} else {
			echo '<label' . ( $field['id'] ? ' for="' . esc_attr( $field['id'] ) . '"' : '' ) . '>' . acf_esc_html( $label ) . '</label>';
		}
	}
}