Break the cache of rtl.css

During WordPress theme or plugin development, when working on stylesheets, it’s sometimes useful to add a version number to a CSS file so that the browser will load the updated version rather than using the cached version.

For a CSS file that is linked or enqueued directly, this is straightforward, but what about the right-to-left support rtl.css that is loaded automatically when present?

Here’s a quick snippet that appends a version number based upon the file modification date:

<?php
/* Break Cache of rtl.css when it is updated */
add_filter( 'locale_stylesheet_uri', function ($localized_stylesheet_uri) {
    $time_ver = filemtime( get_stylesheet_directory() . '/rtl.css' );
    return add_query_arg( array('ver' => $time_ver), $localized_stylesheet_uri );
});
?>

Source: Stackexchange

Leave a Reply