Wordpress child theme - functions.php copy - canno

2019-08-10 15:56发布

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/

标签: php wordpress
1条回答
聊天终结者
2楼-- · 2019-08-10 16:02

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

查看更多
登录 后发表回答