Per Tony’s suggestion, adding a random string to the CSS version did the trick. Here’s the code I used to do that.
First this code to generate the random number.
// get theme version
function cd_get_version() {
$theme_data = wp_get_theme();
return $theme_data->Version;
}
$theme_version = cd_get_version();
global $theme_version;
// get random number
function cd_get_random() {
$randomizr="-" . rand(100,999);
return $randomizr;
}
$random_number = cd_get_random();
global $random_number;
And this this updated code to add that random number to the dynamic CSS file.
function generate_options_css() {
ob_start(); // Capture all output into buffer
require_once dirname( __FILE__ ) . '/inc/custom-styles.php';
$css = ob_get_clean(); // Store output in a variable, then flush the buffer
file_put_contents(dirname( __FILE__ ) . '/inc/custom-styles.css', $css, LOCK_EX); // Save it as a css file
global $theme_version, $random_number;
if (!is_admin()) {
wp_register_style('custom_styles', get_stylesheet_directory_uri() . '/inc/custom-styles.css', false, $theme_version . $random_number);
wp_enqueue_style('custom_styles');
}
}
add_action( 'wp_print_styles', 'generate_options_css' );