How to break CSS cache in WordPress

- Resources, Tips, Tutorials, Lettering

By default, the wp_enqueue_style() function will put whatever version of WordPress that you currently have installed behind your CSS call like this:

<link rel='stylesheet'  href='https://jeradsdesign.com/wp-main/wp-content/themes/jeradsdesign-wp/css/main.css?ver=5.8.2' type='text/css' media='all' />

Grab the theme version from your style.css file:

$theme = wp_get_theme();
define(‘THEME_VERSION’, $theme->Version);

Pass it as the 3rd parameter in your wp_enqueue_style() function in your functions.php:

wp_enqueue_style(‘main’, get_template_directory_uri() .’/css/main.css’, array(), THEME_VERSION);

If your style.css file has “Version: 1.0” in the top commment, it will now output this:

<link rel='stylesheet' href='https://jeradsdesign.com/wp-main/wp-content/themes/jeradsdesign-wp/css/main.css?ver=1.0' type='text/css' media='all' />

Please follow and like us:

January 6, 2022 by Jerad

Tagged: , ,

Reply or Comment

Your email address will not be published. Required fields are marked *


error

Enjoy this blog? Please spread the word :)