简体   繁体   中英

W3 Total Cache does not combine / minify child theme CSS

I have a child theme and W3 Total Cache does all the combining and minification of all the parent theme's CSS files, but the style.css file of my child theme remains outside the combined and minified file. This also breaks my styles, because the order of inclusion of the CSS files is broken. This is how I have included the CSS files of the parent theme - I added the following line in my child theme's functions.php:

function theme_enqueue_styles() {

global $wp_styles;
$parent_style = 'parent-style';

wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
    get_stylesheet_directory_uri() . '/style.css',
    array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

Is there another way of linking the CSS files so that they get properly intercepted by W3 Total Cache?

Try enabling @import handling for child themes .

You also dont need to enqueue the style.css for child theme as its enqueued by default. Instead just enqueue the parent stylesheet.

// Child-theme Functions.php
function theme_enqueue_styles() {

    global $wp_styles;
    $parent_style = 'parent-style';
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );

}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM