Hi, I am trying to use ACF to update theme colours.
Currently I have theme-colors.php:
<?php
header("Content-type: text/css");
$primary = get_field('color', 'option');
?>
body {
color: <?php echo $primary; ?>;
}
This works if I set $primary to a css value. But it’s not pulling the acf field in.
I’ve tried:
get_post_meta( get_the_ID(), 'color', true );
But obviously there’s no ID as it’s coming from options page. Does anyone know how I can use an ACF option in a php file like this?
Thanks.
OK I found:
$primary = esc_html( get_option( 'colour') );
But this is also not working.
I had the same problem and found the solution when I look through the database. I notice ACF ads prefix ‘options_‘ to the field for the options page.
So if your field name is ‘color’, to get the value use it like this
get_option( 'options_colour');