Skip Navigation

Waiting for author

Overview of the issue

W3-Total-Cache is not minifying files correctly for secondary languages when WPML setting default language in directory is active.

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 to resolve this issue

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.

31 Responses to “W3TC is not removing minified files from source”

  1. I had the same issue, and this fixed it!

    Hope that w3 total cache fix it or wpml.

    Will I have to remove the code in “functions.php” when the issue is fixed? right?

    Thanks a lot!

  2. Will it help with minification in all languages directories? Now minification only works on the main language version of the website (main language don’t use directory, simply /). When I switch to another language (e.g. Russian in /ru/), all the original CSS and JS files are loaded and W3 Total cache not minifying them.

  3. Hello, i have problem with w3 total cache and wpml – currently i apply the fixes and that seems to fix some of the problems.
    All plugins are upto date
    I have installed woocommerce lates version.
    One of the problem was on second language my js files didnt work for some reason . ( after applying those fixes its working again ).
    Other problem that didnt fix is when i clear my cache for some reason the products page (product archive) on my second language is not loading the products until i resave the permalinks. Then its working.
    Any ideas ?
    My primary language is Bulgarian and second English.
    Also for some reason at woocommerce i have warning icon – one products is missing translation which is not true. I followed another article how to clear the cache of wpml but that didnt help. I dont know is there any relation between the bugs.

    • According to our records, this hasn’t been fixed and the code still has to be inserted into functions.php
      I will ping our development team to make sure this is scheduled.

      • I got feedback from our developers: the code still has to be inserted into functions.php

        We understand this code should go into w3-totalcache and we shared it all with the author.

        Please note that the PRO version of w3-totalcache doesn’t have this problem, its only the free version.

  4. One question to that. Is it ok to run WPML site with W3TC without minification turned on (by W3TC)? Or is it still necessary to have that fix always for WPML enabled site? On my site minification is provided by Enfold and Cloudflare.
    Thank you.

  5. Hello, after the latest W3TC, WPML and WordPress updates the code provided above doesn’t work anymore. Is there any updated version of the code to fix the problem again. I really need my secondary language’s css & js files minified. I would be thankful for any help. Thank you.

    • It might be that you have lost the changes above after the update, and what you need is reimplement them, if this does not help please let me know, in anyway we are reopening this task to see how we can provide a permanent fix here.

    • Hi there, I have just sent you an email, please come back to me as soon as you can so we can look at and resolve all of the pending issues.

  6. I’ve just noticed the same issue.

    As radekT previously mentioned, he already made a post on the w3 cache forum here:

    https://wordpress.org/support/topic/intended-incompatibility-with-wpml-causes-disfunction/

    And it seems that the w3 team is unwilling to fix the issue and worse, wants to force people to buy their pro version. But even with the pro version there is still the issue with duplicated scripts, as already mentioned in the thread there.

    De facto this means that w3 total cache is broken with WPML. Consequently, I think it should be listed as not compatible here:

    https://wpml.org/plugin/w3-total-cache/

    The workaround from the WPML team works, but obviously it’s not really an acceptable solution to modify plugin code which will get overwritten by the next update.

  7. Please assist. How can I do this code? It has broken all my site and all the language directories.
    I have removed it in the functions.php file but no change

  8. Hey, is this still an isuue?

    I get an error when using it: Parse error: syntax error, unexpected ‘public’ (T_PUBLIC), expecting :: (T_PAAMAYIM_NEKUDOTAYIM)

    /**
    * 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;
    }

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>