2018-02-20 19:34:46 8 Comments

First, sorry my english. I am using Local by flywheel to manager my site files and my wordpress version is 4.9.4.

Here is the problem, When I use

 wp_enqueue_style('wharever', get_stylesheet_uri());

To load style.css at the first time with a just simple content inside:

body { color: orange; }

Everything is just fine, and we have a page with everything in orange text, but when I change the style.css body color to green (or whatever), they just don't change, and always are orange.

PS.: in wp_enqueue_style, I changed the version parameter and he changes, but only at the first time and stuck with the first color I put for the version that was put.

If this is a feature of wordpress, how can I turn this off? This don't see quite useful know that we can't change style.css at will just to test without change version.


@majick 2018-02-21 00:00:11

Another solution is to use filemtime for the cachebusting, so that the last modified timestamp is used as the querystring variable.

This has the advantage that of still using the browser cache, and yet, a new file is served when the file is actually changed because the querystring changes. eg.

$lastmodtime= filemtime(get_stylesheet_directory().'/style.css');
wp_enqueue_style('whatever', get_stylesheet_uri(), array(), $lastmodtime);

@n8bar 2018-03-02 23:19:57

Great idea. This way it still safely uses caching when the file hasn't changed. Thanks.

@n8bar 2018-02-20 22:39:30

It is a caching problem. To get around this I append a random string to the stylesheet uri that discourages the browser from caching it.

First you need a random string. I use this simple function to generate one.

function randomAlphaNumeric($length) { $pool = array_merge(range(0,9), range('a', 'z'),range('A', 'Z')); $key=''; for($i=0; $i < $length; $i++) { $key .= $pool[mt_rand(0, count($pool) - 1)]; } return $key; }

Now just use it in your enqueue like this:

wp_enqueue_style('wharever', get_stylesheet_uri().'?random='.randomAlphaNumeric(5));

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] dynamic name of the style for wp_enqueue_style

1 Answered Questions

wp_enqueue_style specifics for overwriting plugin styles

1 Answered Questions

[SOLVED] wp_enqueue_style with style.php and Wordpress functions

1 Answered Questions

[SOLVED] Stuck with Enqueue Styles for multiple css files in a child theme

  • 2016-03-07 21:44:03
  • user90158
  • 1689 View
  • 0 Score
  • 1 Answer
  • Tags:   wp-enqueue-style

1 Answered Questions

[SOLVED] Double jQuery loaded

1 Answered Questions

[SOLVED] Unable to load stylesheet via wp_enqueue_style

0 Answered Questions

Checkbox doesn't stay checked, conten

  • 2013-06-27 08:35:19
  • Maartje
  • 162 View
  • 1 Score
  • 0 Answer
  • Tags:   php loop

2 Answered Questions

2 Answered Questions

[SOLVED] How to enqueue the style using wp_enqueue_style()

  • 2013-03-05 14:02:59
  • Mayeenul Islam
  • 37996 View
  • 4 Score
  • 2 Answer
  • Tags:   wp-enqueue-style

1 Answered Questions

[SOLVED] wp_enqueue_style in Plugin

Sponsored Content