• Resolved cwrichardson

    (@cwrichardson)


    The recommended way to include stylesheets these days, per Child Themes, is

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        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')
        );
    }

    And that’s basically what you guys do in your supplied child theme. Unfortunately (and this isn’t just your problem, it’s a problem with many themes), because you use multiple style sheets, this results in broken dependencies. If done the recommended way, the order of style sheets comes out:

    parent
    child
    flat_responsive_bootstrap
    flat_responsive_font-awesome
    flat_responsive_menu_css

    You don’t immediately notice problems, but some do pop up. For example, when done this way, the pancake icon never turns visible.

    I fixed it for myself by doing two things. First, change the parent theme to always call the main stylesheet, and make it depend on those three, so it comes out in the correct order.

    From:

    // Loads our main stylesheet.
     wp_enqueue_style( 'flat_responsive-style', get_stylesheet_uri(), array(), current_time( 'mysql' ) );

    To:

    // Loads our main stylesheet.
    wp_enqueue_style( 'flat_responsive-style', get_template_directory_uri() . '/style.css', array('flat_responsive-bootstrap', 'flat_responsive_font-awesome',
    'flat_responsive_menu_css'), current_time( 'mysql' ) );

    NB: get_stylesheet_ui() will get the child stylesheet, even if called in the parent themes function.php.

    Then, in the child theme, instead of enqueueing the parent stylesheet, register the child stylesheet with a dependency on flat_responsive-style:

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
            wp_register_style('child-style', get_stylesheet_directory_uri()
                . '/style.css', array('flat_responsive-style'));
            wp_enqueue_style('child-style');
    }

    WordPress probably needs to come up with a better recommended solution (e.g., tell theme authors to always call their last encoded stylesheet “parent”, and then change the child recommendation to put a dependency on parent). Or something.

    But, in the meantime, since you’re providing a child theme skeleton anyhow, you can do the above to ensure correct stylesheet ordering.

    Or you can do something else entirely ??

    In any case … hopefully this helps someone (and hopefully it or a similar solution gets made in the theme, so things don’t break next time I update the parent ?? ).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author Styled Themes

    (@gejay)

    Hi cwrichardson,

    Thanks for your suggestion, in the mean time we haven’t supplied any child theme for flat responsive, so we will make sure to look at the things that you have mentioned.

    Thanks

    This just helped me cwrichardson.

    I was searching for such a solution. Rather than create a child theme manually I used the plugin ‘One-Click Child Theme’ which created a child theme editable from the WP dashboard. It created the functions.php, style.css, rtl.css and screenshot.png files.

    I couldn’t get the pancake menu to work and was losing the traditional menu when I shrank browser or accessed from my mobile.

    So, I modified the parent functions.php file this way so as to not get rid of the original code:

    //START REPLACEMENT BY JH 7/15/15:
    // Loads our main stylesheet.
    //wp_enqueue_style( ‘flat_responsive-style’, get_stylesheet_uri(), array(), current_time( ‘mysql’ ) );
    wp_enqueue_style( ‘flat_responsive-style’, get_template_directory_uri() . ‘/style.css’, array(‘flat_responsive-bootstrap’, ‘flat_responsive_font-awesome’,
    //END REPLACEMENT

    I then changed the child theme functions.php by doing this:

    // OLD CHILD THEME SECTION START
    // add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
    // function theme_enqueue_styles() {
    // 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’)
    // );
    // }
    // OLD CHILD THEME SECTION END
    // REPLACE WITH THIS…

    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
    function theme_enqueue_styles() {
    wp_register_style(‘child-style’, get_stylesheet_directory_uri()
    . ‘/style.css’, array(‘flat_responsive-style’));
    wp_enqueue_style(‘child-style’);
    }
    // END REPLACEMENT

    Yah, it’s not pretty but, it will help me later when I try to remember what I did (eg. modifying the parent functions.php).

    Thanks much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Child Themes break styling (responsive, dependencies, mobile, menu icon)’ is closed to new replies.