Till now in my Wordpress themes, I was implementing few necessary styling options in theme customizer which would edit the CSS and override it by outputting that CSS to head inside <style>
tags, for example here I implemented color picker and I output the styles if the default state is changed:
function dc_get_gradient_colors() {
$first_color = get_theme_mod( 'primary_color_1' );
if ( $link_color != '#000000' ) :
?>
<style type="text/css">
.main-color-1-color{
color: <?php echo $link_color; ?> !Important;
}
.main-color-1-background-color{
background-color: <?php echo $link_color; ?> !Important;
}
.main-color-1-border-color{
border-color: <?php echo $link_color; ?> !important;
}
</style>
<?php
endif;
}
add_action( 'wp_head', 'get_gradient_colors' );
Is there any better way for doing this, including editing CSS file directly. I know that stylesheet can be in form of PHP file, so there I could put the conditionals depending on theme options. But is that the best way, or is there way to write to style.css from theme customizer?
style.css
by having CSS inline or in a file appear after it, with a higher specificity, that part isn't a WP thing. Since what you have already works I'd stick with it