Add to theme.json (add proper color palette to custom ACF blocks):
{
"settings": {
"blocks": {
"acf/block-name": {
"color": {
"background": true,
"palette": [
{
"slug": "primary-color",
"color": "#007991",
"name": "Primary"
},
{
"slug": "white",
"color": "#ffffff",
"name": "white"
}
]
}
}
}
}
}
Add when registering custom block (enables use of the theme.json colors):
<?php
'supports' => [
'color' => true // for both background and text
'color' => [
'background' => true // for background color only
]
]
Add to custom block php file (add color classes to custom block output on front end):
<?php
// to add background color class
if ( ! empty( $block['backgroundColor'] ) ) {
$classes .= ' has-' . $block['backgroundColor'] . '-background-color has-background';
}
// to add text color class
if ( ! empty( $block['textColor'] ) ) {
$classes .= ' has-' . $block['textColor'] . '-color has-text-color';
}