Francesca Francesca - 1 year ago 138
PHP Question

Wordpress child theme - functions.php copy - cannot "redeclare"

I'm using Starkers with a child theme (starkers-child).

I need to edit the functions.php to declare a menu, so I copied down the functions.php, JS folder and external folder (which were all declared somewhere in the functions file)

However I still have one error:

Cannot redeclare starkers_script_enqueuer()
(previously declared in C:\wamp\www\redlaw\wp-content\themes\starkers-child\functions.php:65) in

I believe it is caused by this line:

function starkers_script_enqueuer() {

I can see why as it already calls the function in the master, so it cannot call it again in the child.

But if I remove this line from the master then doesn't that defeat the purpose of keeping a clean master and having a child theme?

Full functions.php is here (unedited, as it appears in the master theme)

Answer Source

Forgive me, I don't have enough rep to just comment.

A child theme's functions.php is loaded in addition to the parent theme. So you don't need to actually copy and paste the code. What everyone else says about wrapping it in an if(function_exists(function)) is optional, but a best practice because it's less error prone.


This is from the Codex:

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

Read more here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download