- Status
- Resolved
- Related plugin/theme
- W3 Total Cache
Overview of the issue
W3-Total-Cache is not minifying files correctly for secondary languages when WPML setting default language in directory is active.
Please note: Only the Pro version is compatible with WPML.
Workaround
To enable minifying files, add following code to functions.php
function wpml_comp_2347( $data ){
if ( did_action( 'wpml_loaded' ) ) {
$home_url = $data['home_url'];
if ( substr( $data['url'], 0, strlen( $home_url ) ) != $home_url ) {
$data['home_url'] = get_option( 'home' );
}
}
return $data;
}
add_filter( 'w3tc_url_to_docroot_filename', 'wpml_comp_2347', 20 );
Fix removing minified files from queue, change following function in W3TC code:
wp-content/plugins/w3-total-cache/Util_Environment.php
/**
* Returns home url regexp
*
* @return string
*/
static public function home_url_regexp() {
$home_url = get_option('home');
$regexp = Util_Environment::get_url_regexp( $home_url );
return $regexp;
}
Next steps
We understand that having to edit your functions.php is not ideal and as such, we have repeatedly tried to reach out to the W3 Total Cache team to get this issue resolved. Our current understanding is that the Pro version is compatible with WPML, but the free version is not. If you’d like to speak to the W3 Total Cache team about resolving this issue, please do contact them via their free support channel.