WPML

Overview of the Issue

W3-Total-Cache is not minifying files correctly for secondary languages when WPML setting default language in directory is active. This also affects the secondary languages when you use directories for languages (tested with W3 Total Cache 2.11.0).

Please note: Only the Pro version is compatible with WPML.

Workaround

To enable minifying files, add following code to functions.php

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
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 (opens in a new tab).

All known issues

Need Help with This Issue?

Ask a support question and we’ll look into it with you.