Home › Forums › General Issues › Conditional Fields – Color or Image – Add Via Dynamic Style Sheet › Reply To: Conditional Fields – Color or Image – Add Via Dynamic Style Sheet
1) Absolutely. Set up the radio button field with two values: image and color (you can label them whatever you like). Set up the color picker field, set up the image field. Set the color and image fields to only display when the related radio button is selected via “Conditional Logic” at the bottom of their respective fieldsets.
2) I’d probably do this with inline css to save the headache. Set any sort of global stuff in your stylesheet and then in the template something along the lines of this should get you going:
<?php
$backgroundType = get_field('the-type-radio-button-field-name');
if ($backgroundType == "image"){
$style = "background-image: " . the_field('your-image-field-name');
} else { //it's a color
$style = "background-color: " . the_field('your-color-picker-field');
}
?>
<div style="<?php echo $style; ?>">
Content Here.
</div>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.