Home › Forums › Front-end Issues › ACF/PHP in CSS › Reply To: ACF/PHP in CSS
Thank you John for your reply, however I found another solution although its still early days of testing yet:
I managed to create a file called main.css.php where I put only my css code and the ACF php code and then added this to my functions file:
function generate_options_css() {
ob_start(); // Capture all output into buffer
require_once dirname( __FILE__ ) . '/main.css.php';
$css = ob_get_clean(); // Store output in a variable, then flush the buffer
file_put_contents(dirname( __FILE__ ) . '/main.new.css', $css, LOCK_EX); // Save it as a css file
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/main.new.css' );
}
add_action( 'wp_enqueue_scripts', 'generate_options_css' );
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.