0

I am looking for help on understanding how child themes and parent themes functions.php work.

I know with CSS, the cascade overrides CSS declared earlier in the style sheet. It is my understanding that the functions.php does not operate the same way. I understand that both functions.php are loaded.

What happens if you want to have the function in the child theme override a function in the parent theme and the parent theme is not using if statements like the codex recommends?

0

2 Answers 2

0

The comparison of CSS and functions.php files is pretty flawed. PHP doesn't "cascade".

To answer your question, both files are loaded, child theme functions.php first then the parent's.

What happens if you want to have the function in the child theme override a function in the parent theme and the parent theme is not using if statements like the codex recommends?

You mean, if the parent function is not wrapped in function_exists conditional? Then you can't override the function. That is basic PHP. Try to re-declare a function and you will get an error. You can't get around that. The best you can do is hope for a filter that will let you do what you need, and contact the parent theme developer.

This answer might be of interest.
Or this one

0

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.)

Wordpress Codex here to find.

Not the answer you're looking for? Browse other questions tagged or ask your own question.