• Hi! Your plugin is great and useful indeed, thank you for your work.

    But I have some troubles with stylesheets combining.

    Stylesheets attached by functions.php with following code:

    add_action('init', 'my_custom_css_stylesheet', 0);
    function my_custom_css_stylesheet() {
        wp_register_style( 'custom-style-one', get_stylesheet_directory_uri() . '/libs/OwlCarousel2/assets/owl.carousel.min.css' );
        wp_register_style( 'custom-style-two', get_stylesheet_directory_uri() . '/libs/OwlCarousel2/assets/owl.theme.default.min.css' );
        wp_register_style( 'custom-style-three', get_stylesheet_directory_uri() . '/libs/Choices/choices.min.css' );
    }
    wp_enqueue_style( 'custom-style-one' );
    wp_enqueue_style( 'custom-style-two' );
    wp_enqueue_style( 'custom-style-three' );
    
    function attach_style_articles() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style-article.css' );
    }
    function attach_style_basket() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style-basket.css' );
    }
    function attach_style_home() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style.css' );
    }
    function attach_style_landing() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style-index2.css' );
    }
    function attach_style_product() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style-product.css' );
    }
    function attach_style_shop() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style-goods.css' );
    }
    function attach_style_other() {
    	wp_enqueue_style( 'wpdocs-header-new-style', get_template_directory_uri() . '/css/style-articles.css' );
    }
    
    function wpdocs_themeslug_header_hook( $name ) {
    	if ( 'articles' == $name ) {
    		add_action( 'wp_enqueue_scripts', 'attach_style_articles' );
    	}
    	elseif ( 'basket' == $name ) {
    	    add_action( 'wp_enqueue_scripts', 'attach_style_basket' );
    	}
    	elseif ( 'home' == $name ) {
    	    add_action( 'wp_enqueue_scripts', 'attach_style_home' );
    	}
    	elseif ( 'landing' == $name ) {
    	    add_action( 'wp_enqueue_scripts', 'attach_style_landing' );
    	}
    	elseif ( 'product' == $name ) {
    	    add_action( 'wp_enqueue_scripts', 'attach_style_product' );
    	}
    	elseif ( 'shop' == $name ) {
    	    add_action( 'wp_enqueue_scripts', 'attach_style_shop' );
    	}
    	else {
    	    add_action( 'wp_enqueue_scripts', 'attach_style_other' );
    	}
    }
    add_action( 'get_header', 'wpdocs_themeslug_header_hook' );

    It looks like plugin can’t get stylesheets attached this way, am I right? Is it possible to fix somehow?

    • This topic was modified 2 years, 3 months ago by spoul.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmm … might this be a permissions problem? does the user under which the PHP process run have read-access to those files?

    Thread Starter spoul

    (@spoul)

    Yes, it looks like all permissions are set right way. The plugin has access to other css files, including those located in the template folder. Take a look in the source code of page. Links to combined files are visible there.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmm .. can you try tweaking the code so that it includes has the full URL (so also host/ domain name)?

    Thread Starter spoul

    (@spoul)

    Instead of get_template_directory_uri() you mean?

    Done in this part of code

    add_action('init', 'my_custom_css_stylesheet', 0);
    function my_custom_css_stylesheet() {
    /*
        wp_register_style( 'custom-style-one', get_stylesheet_directory_uri() . '/libs/OwlCarousel2/assets/owl.carousel.min.css' );
        wp_register_style( 'custom-style-two', get_stylesheet_directory_uri() . '/libs/OwlCarousel2/assets/owl.theme.default.min.css' );
        wp_register_style( 'custom-style-three', get_stylesheet_directory_uri() . '/libs/Choices/choices.min.css' );
    */
        wp_register_style( 'custom-style-one', 'https://gmk-nasos.ru/assets/themes/gmk-t/libs/OwlCarousel2/assets/owl.carousel.min.css' );
        wp_register_style( 'custom-style-two', 'https://gmk-nasos.ru/assets/themes/gmk-t/libs/OwlCarousel2/assets/owl.theme.default.min.css' );
        wp_register_style( 'custom-style-three', 'https://gmk-nasos.ru/assets/themes/gmk-t/libs/Choices/choices.min.css' );
    }
    wp_enqueue_style( 'custom-style-one' );
    wp_enqueue_style( 'custom-style-two' );
    wp_enqueue_style( 'custom-style-three' );

    On front source got three links instead of combined one

    <link rel='stylesheet' href='https://gmk-nasos.ru/assets/themes/gmk-t/libs/OwlCarousel2/assets/owl.carousel.min.css' />
    <link rel='stylesheet' href='https://gmk-nasos.ru/assets/themes/gmk-t/libs/OwlCarousel2/assets/owl.theme.default.min.css' />
    <link rel='stylesheet' href='https://gmk-nasos.ru/assets/themes/gmk-t/libs/Choices/choices.min.css' />
    • This reply was modified 2 years, 3 months ago by spoul.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmm .. still no idea. is the problem only with the theme, or also with plugin JS/ CSS?

    Thread Starter spoul

    (@spoul)

    As I can see, it’s only with theme assets.

    Have no place this moment to test with clean theme functions.php and this way to attach css files.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    first thing to do (if you have time) is to briefly switch to default theme to confirm those CSS/ JS files are aggregated OK?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Autoptimize ignores some styles’ is closed to new replies.