Skip to content

Instantly share code, notes, and snippets.

@Mte90 Mte90/snippet.php

Created Apr 30, 2020
Embed
What would you like to do?
W3TC generate minified filename by checksum
<?php
// Based on https://wordpress.org/support/topic/how-to-change-minified-css-file-name/
// Get all the files, read them, concat them, get a md5 hash, cut at 10 and generate a new filename
// Why?
// W3TC generate the hashname based on the filenames so not invalidate the cache if there are changes
add_filter('w3tc_minify_urls_for_minification_to_minify_filename', 'w3tc_filename_filter', 20, 3);
function w3tc_filename_filter($minify_filename, $files, $type ){
$path_parts = pathinfo( $minify_filename );
$content = '';
foreach ( $files as &$asset ) {
$content .= file_get_contents( ABSPATH . '/' . $asset );
}
return substr( md5( $content ), 10 ) . '.' . $path_parts[ 'extension' ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.