I have been searching for days now and I have tried countless times but all the examples I have tried are not working. I have a field that pulls a variable and I want to change the color of the text based on the selection of that variable. So if the variable is set to Undecided I want the text to change to red but if any other option is selected I want it to remain black. This is the line of code on the template for the page that pulls the variable which is currently working correctly:
<p id="orient" style="color:#<?php echo $style; ?> "><strong>Orientation: <?php echo get_field('orientation',get_the_ID()); ?></strong></p>
I then tried a bunch of ways but this is what I am currently trying to get to work:
var ori = "<?php echo get_field('orientation',get_the_ID()); ?>";
if ($ori == "Undecided") {
$style="FFF";
};
I keep getting an error saying the variable is undefined but I do not understand why? What am I doing wrong here? How do I set the variable correctly? Or is there a better way to do this?
question from:
https://stackoverflow.com/questions/65923155/change-css-color-of-text-based-on-php-variable 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…