Site icon Hip-Hop Website Design and Development

Get title color from category custom field

I have installed Advanced Custom Fields and created a color custom field for categories.

Now I want to achieve two things:

1- Display the title text of the post in the color selected in the category custom field.
2- Display category name with the background selected in the category custom field.

I’m using GeneratePress theme and hooking the inline css using the Generatepress hooks. Here’s the code:

$term = get_queried_object();
$color = get_field('color', $term);
?>

<style>
    .wp-block-post-title {
        color: <?php echo $color; ?> !important;
    }
</style>

The problem is that $color variable is not populating the color value from the custom field. When I hardcode the color e.g., #000, the code works perfectly fine.

Please tell me what I’m doing wrong in the code? Thank you.