ข้ามการนำทาง

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 การตอบกลับ ถึง “W3TC is not removing minified files from source”

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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;
    }

ทิ้งคำตอบไว้

โปรดอยู่ในหัวข้อและเคารพผู้อื่น หากคุณต้องการความช่วยเหลือเกี่ยวกับปัญหาที่ไม่เกี่ยวข้องกับโพสต์นี้ โปรดใช้ฟอรัมสนับสนุนของเราเพื่อเริ่มการสนทนาหรือส่งตั๋ว.

คุณสามารถใช้แท็กเหล่านี้:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>