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__ ) . '/', $css, LOCK_EX); // Save it as a css file
    	wp_enqueue_style( 'main_css', get_template_directory_uri() . '/' );
    add_action( 'wp_enqueue_scripts', 'generate_options_css' );