• Resolved esemlabel

    (@esemlabel)


    Hi!

    I’m using child theme with overriding parrent theme styles.
    The promblem is in duplicating style classes. After activating option “Optimize CSS Code” there is some bug on page reload (CTRL+F5). For some reason it apply some strange styles for half a second, that are not visible when option is disabled. So website design just for a moment on load looks strange. Optimized css file stores both style classes – original and overring.

    Maybe such scenario would fix it.
    1. get parent theme css first.
    2. get child theme css.
    3. remove styles from parent theme that are in the child (parent theme styles minus child theme styles (styles in classes, but now whole classes complitely)).
    4. split styles (parent theme style plus child theme style).

    Enabling “Inline all CSS” option fix the problem, but it is not what I need.

    Screenshots (after activating option “Optimize CSS Code”).
    1. blue text instead of white with little move-in effect (it is really set to white in both parent and child theme, but for some reason shows blue): http://oi59.tinypic.com/vq6v41.jpg
    2. sliding forms from right screen side (problem doesn’t appers when option is disable) and blue text again: http://oi60.tinypic.com/33p7szs.jpg
    3. and so on ..

    P.s. I was able to reproduce the issue only with non-admin login.

    Thank you!

    https://wordpress.org/plugins/autoptimize/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter esemlabel

    (@esemlabel)

    Maybe the reason is that the order of styles and classes in optimized file doesn’t match original order of files and css styles. For example, if on page styles and styleshits order is: some file with styles, after that wp_enqueue_script, then some other style, – then the optimized file with css styles should match the original order styles and classes in it’s file (styles from first file at the beginning, then styles from wp_enqueue_script, then other styles, etc.).

    And why the problem doesn’t appear on website when admin account is used..?

    Plugin Author Frank Goossens

    (@futtta)

    For some reason it apply some strange styles for half a second, that are not visible when option is disabled. So website design just for a moment on load looks strange.

    So “in the end” the site looks OK? Did you exclude some CSS from being autoptimized? Or do you have CSS pulled in from another domain?

    remove styles from parent theme that are in the child (parent theme styles minus child theme styles (styles in classes, but now whole classes completely).

    that would require some advanced CSS-intelligence in AO, which I think would be to complex and frail to do.

    Maybe the reason is that the order of styles and classes in optimized file doesn’t match original order of files and css styles.

    No, AO typically honors the original order actually.

    My best guess; although AO aggregates & minifies the CSS, there is part of it which AO does not aggregate (reasons: excluded in settings, generated by PHP or external CSS), which is applied just before or just after the AO-CSS. The time between these different CSS-files being loaded causes the brief “Flash Of (partly) Unstyled Content”.

    hope this helps,
    frank

    Thread Starter esemlabel

    (@esemlabel)

    So “in the end” the site looks OK? Did you exclude some CSS from being autoptimized? Or do you have CSS pulled in from another domain?

    Yes, “in the end” it looks fine. I didn’t exclude any css, because I don’t know where to start with. All website css files are stored localy on my localhost testing server.

    There are definitely no external CSS.
    I will try to locate “promblem” css by disabling each file and inline css step-by-step. I hope I will find solution.

    Thank you for the fastest feedback! You’rethe best developers!

    Thread Starter esemlabel

    (@esemlabel)

    Good news!
    I found the reason why it’s happend.

    The reason is in this code:

    if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
        function chld_thm_cfg_parent_css() {
            wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css' );
        }
    endif;
    add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css' );

    It is automatically generated code by https://wordpress.org/plugins/child-theme-configurator/ of child function.php. This code load child theme style right after parent theme style.css.

    After disabling this code – all becomes normal. But it works if “Optimize CSS Code” option is enabled at the same time. For example,

    disalbe AO + keep enable those code in function.php – works fine!
    enable AO + keep enable those code in function.php – doesn’t work.
    enable AO + disable those code in function.php – works fine!

    I suppose WordPress versions of past years doesn’t require such code.
    Otherwise it need to re-enable those code in function.php in future when AO plugin will be deactivated. Hopes this help for others, who uses the same function.

    You can close topic. Thanks a lot!

    Plugin Author Frank Goossens

    (@futtta)

    great find, happy it works esemlabel!

    frank

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Optimize CSS Code › Child-theme style issue’ is closed to new replies.