acf_merge_attributes()
acf_merge_attributes
Merges together two arrays but with extra functionality to append class names.
No Hooks.
Returns
Array.
Usage
acf_merge_attributes( $array1, $array2 );
- $array1(array) (required)
- An array of attributes.
- $array2(array) (required)
- An array of attributes.
Changelog
| Since 5.7.10 | Introduced. |
acf_merge_attributes() acf merge attributes code ACF 6.0.4
function acf_merge_attributes( $array1, $array2 ) {
// Merge together attributes.
$array3 = array_merge( $array1, $array2 );
// Append together special attributes.
foreach ( array( 'class', 'style' ) as $key ) {
if ( isset( $array1[ $key ] ) && isset( $array2[ $key ] ) ) {
$array3[ $key ] = trim( $array1[ $key ] ) . ' ' . trim( $array2[ $key ] );
}
}
// Return.
return $array3;
}