Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

wordpress

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 
C:\wamp\www\redlaw\wp-content\themes\starkers-master\functions.php

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) http://jsfiddle.net/8KGcK/

like image 985
Francesca Avatar asked May 05 '26 17:05

Francesca


1 Answers

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.

Anyways!

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

like image 69
Morklympious Avatar answered May 08 '26 09:05

Morklympious