search ]

Cache Busting and Versioning for rtl.css

Do you load the rtl.css file using the automatic method WordPress provides? That is, adding the rtl.css file to your theme directory so that when the site language is set to right-to-left (RTL), this file loads automatically. It is the preferred way to load RTL-specific CSS for RTL sites.

However, this file has no version (no query string), which makes cache busting difficult in the browser, especially for this file (if you are not using a caching plugin).

The Query String mentioned above

To add the ver parameter to the rtl.css file based on when the file was last modified, use the following filter:

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 );
});
Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo