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.
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!
Hi Roger,
yes – after issue is officially fixed, you can remove code.
We’re glad it helped.
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.
Yes, this fix will help to remove minified files on pages in other language.
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.
Hello Martin,
we’re happy this fix resolved some of issues.
As I understand – it fixed exactly what’s expected.
About WooCommerce permalinks and product translation,
please report it on our support forum here:
https://wpml.org/forums/forum/english-support/
Our support will gladly help.
Hi, has this issue been fixed, or does the code still have to be inserted into functions.php
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.
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.
Yes, you can can WPML and W3TC without requiring minification for resource files.
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.
After update of W3TC tha changes made in wp-content/plugins/w3-total-cache/Util_Environment.php are lost.
Please, did W3TC confirm, that they will implement this?
Hi, we have reported that I am rechecking with them the state of the fix and I’ll update you here.
I made a related comment at https://wordpress.org/support/topic/intended-incompatibility-with-wpml-causes-disfunction/
Hello WPML support,
I am writing regarding this post:
https://wordpress.org/support/topic/intended-incompatibility-with-wpml-causes-disfunction/
We should discuss improving compatibility for our extension in your post. Please drop us a note at https://www.w3-edge.com/contact/.
Best Regards,
W3 Total Cache Support
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.
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.
This fix no longer seems to work. Is there an updated solution?
Hi, any update about this fix?
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
I am sorry about this! One of our developers is looking at this and we’ll come back to you with an answer ASAP.
Hi Amit,
were you able to find a solution to the problem?
I am sorry but we have not, it is queued and will be looked at but I can not share any ETA for now.
W3TC says there must be changed something on both sides. It’s reported here as well: https://wordpress.org/support/topic/stuck-on-version-0-9-7/#post-12459699
Thanks! I. will pass that support link to our developers, this is not scheduled yet on our side as well.
Hi there,
is there any news regarding the issue? It’s still appears to be relevant.
Hello there,
So far this erratum is still valid.
I hope it helps.
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;
}
Hello there,
This workaround shouldn’t display that error. Could you please open a ticket in our support forum so we can investigate it better?