Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Last active February 24, 2022 17:52
Show Gist options
  • Save Asikur22/1aebfd4f981c7e539a2c010412ba1da8 to your computer and use it in GitHub Desktop.
Save Asikur22/1aebfd4f981c7e539a2c010412ba1da8 to your computer and use it in GitHub Desktop.
[CSS/JS/Image Cache Busting] #DisableCache #dev
/*
* Change img src for disable img cache.
* @TODO remove on Production.
*/
function wpse_84670_time_as_img_version($src) {
$src[0] = add_query_arg('dummy', time(), $src[0]);
return $src;
}
add_filter('wp_get_attachment_image_src', 'wpse_84670_time_as_img_version');
/*
* Disable CSS/JS Cache
*/
function wpse_84670_time_as_version( $url ) {
if ( strpos( $url, 'fonts.googleapis.com' ) !== false || strpos( $url, 'font-awesome' ) !== false ) {
return $url;
}
return add_query_arg( array( 'ver' => time() ), $url );
}
add_filter( 'script_loader_src', 'wpse_84670_time_as_version' );
add_filter( 'style_loader_src', 'wpse_84670_time_as_version' );
/*
* Disable CSS/JS Cache
*/
function wpse_84670_time_as_version( $url ) {
return add_query_arg( array( 'ver' => time() ), $url );
}
add_filter( 'script_loader_src', 'wpse_84670_time_as_version' );
add_filter( 'style_loader_src', 'wpse_84670_time_as_version' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment