CSS not updating in browser when I change it

Add a random version number at the end of the css file you are attaching. If you are using ‘wp_enqueue_style‘ or wp_register_style functions, pass a random (version) number rand(111,9999) to 4th parameter. If you are attaching css as an html tag, you should add “?ver=<?php echo rand(111,999)?>” at the end of the file name. Examples are here

wp_register_style( 'custom-style', get_template_directory_uri() . '/css/custom-style.css', array(), rand(111,9999), 'all' );

or

<link rel="stylesheet" type="text/css" href="http://website.com/css/custom-style.css?ver=<?php echo rand(111,999)?>">

It will avoid caching on client end caching and possibly server caching too.

Leave a Comment