theme development – WordPress force refreshing css on every change

Question

Every time I do change to CSS (through SCSS code) I have to clear cache in the browser to load new css.
I want to avoid that (especially in production for users).

This is my function (child template) code:

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
    function chld_thm_cfg_locale_css( $uri ){
        if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
            $uri = get_template_directory_uri() . '/rtl.css';
        return $uri;
    }
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );

if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
    function chld_thm_cfg_parent_css() {
        wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'bootstrap','newsup-style','light','font-awesome','owl-carousel','smartmenus' ), rand(111,9999), 'all' );
    }
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );
         
if ( !function_exists( 'child_theme_configurator_css' ) ):
    function child_theme_configurator_css() {
        if ( !file_exists( trailingslashit( get_stylesheet_directory() ) . 'newsup-style.min.css' ) ):
            wp_deregister_style( 'newsup-style' );
            wp_register_style( 'newsup-style', trailingslashit( get_template_directory_uri() ) . 'newsup-style.min.css' );
        endif;
        wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'chld_thm_cfg_parent' ), rand(111,9999), 'all' );
    }
endif;
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 10 );

// END ENQUEUE PARENT ACTION

I use WP-SCSS plugin: https://wordpress.org/plugins/wp-scss/

And in style.css I import compiled custom.css

@import './css/custom.css';

I checked some solutions and was trying to add random numeber or time() (see above), but maybe I am doing this wrong.

0
Filip Witkowski 5 months 2022-03-11T09:11:43-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse