I am making a custom theme in WordPress. I am using the ACF plugin to make things dynamic. I have created an options page where users can select the color which needs to be displayed on the website. So for that, I converted the common style.css to common-style.php and linked the common style.php in function.php but I am not able to achieve the background color.
<?php
header(“Content-type: text/css; charset: UTF-8″); //look carefully to this line
$primary_color = ” get_field(‘primary_theme_color’, ‘option’);”;
?>
<style type=”text/css”>
–primary-color: <?php echo $primary_color; ?>;
</style>
You cannot use ACF in a php file like this. WP is not set up and no WP or ACF functions will work in the file.
To do dynamic styles in with ACF you have 3 choices.
1) Put the styles inline in the in the ducument
2) Use admin-ajax.php to generate the style css.
3) Generate a static CSS file on changes
https://stackoverflow.com/questions/13001922/how-do-you-handle-dynamic-css-in-wordpress
I generally just put it inline. You’re not going to be generating a lot of styles and it’s more efficient and results in better performance to include small chunks of CSS inline.