• I’m trying to implement a child theme and it appears that what I thought I knew about how they work isn’t accurate.

    Correct me if I’m wrong, but what I understand is that the child theme’s style.css OVERRIDES the parent’s style.css, while the child theme’s function.php is APPENDED to the parent’s function.php.

    So, does that mean the code in the child’s function.php CANNOT exist in the parent (any differences in the child will simply be added to the parent?) — however, anything in the child’s style.css CAN exist in the parent with the child simply taking precedence over anything that is the same in the parent?

    Does that make any sense?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    but what I understand is that the child theme’s style.css OVERRIDES the parent’s style.css

    It doesn’t necessarily, it really just appends onto it. If your Child Themes styles override the parent theme’s, then that is due to CSS specificity and not an underlying principle that this overriding occurs.

    Thread Starter brookskim

    (@brookskim)

    It doesn’t necessarily, it really just appends onto it. If your Child Themes styles override the parent theme’s, then that is due to CSS specificity and not an underlying principle that this overriding occurs.

    Okay, so if I wanted to take an existing theme that has been customized, and make a child theme from it — I would cut out just the customized code from style.css and function.php and put them in the child?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Yes, that sounds right.
    http://codex.wordpress.org/Child_Themes

    Thread Starter brookskim

    (@brookskim)

    Great, let me give that a shot. Thanks.

    Thread Starter brookskim

    (@brookskim)

    Okay, I’ve been experimenting with this for the past 2 hours and here’s what I’ve discovered. Everything with style.css is working the way it should. But here’s the odd thing with the functions.php file.

    I installed a brand new theme and created a child theme for it. I then cut out an “if function exists” section from the parent put it into a new functions.php file in the child theme. So, at this point, the only thing the child’s functions.php file has is this particular “if function exists” code.

    After this, everything looked normal when viewing the child theme, as expected. The code from the child was evidently appended to the parent.

    But then, I modified that code and put it back in the parent. So now the child has the original code and the parent has the modified code. They’re both within the same “if function exists” tags.

    When I did this, the child theme’s code completely overwrote the parent, instead of appending it. I exchanged the code between parent and child, and saw the same behavior.

    Am I missing something?

    Yes.

    Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    Thread Starter brookskim

    (@brookskim)

    Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

    Right, I understand that, but what I’m saying is that my child theme’s functions.php file IS overriding its parent counterpart.

    Thread Starter brookskim

    (@brookskim)

    Okay, I think here’s what’s happening. My knowledge of php is basically what I’ve learned in the past few hours, so please excuse the lack of correct terminology.

    Anyway, when the parent and child have different code within the same conditional tags, the child’s code will be used, having the same effect as overriding the parent. I’m assuming this is because php code can’t be appended from child to parent within the same tags. However, anything new outside of those tags will be appended.

    I don’t know if that’s how it works, but it makes sense if it does. I think.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Child theme confusion’ is closed to new replies.