admin管理员组文章数量:1122846
I'm creating and installing a child theme for the first time. There are only a few edits to the style.css and one to the functions.php file. Do I need to copy the entire parent style.css into the child directory and then include my edits or do I just include my edits in the child style.css with no other code and the two files (parent and child) will be combined when installing? Likewise, since I'm changing the functions.php file in a couple spot (my edit and addition of the engueue), do I copy the whole functions.php file into the child theme directory or just include the edits in the child functions.php file?
I'm creating and installing a child theme for the first time. There are only a few edits to the style.css and one to the functions.php file. Do I need to copy the entire parent style.css into the child directory and then include my edits or do I just include my edits in the child style.css with no other code and the two files (parent and child) will be combined when installing? Likewise, since I'm changing the functions.php file in a couple spot (my edit and addition of the engueue), do I copy the whole functions.php file into the child theme directory or just include the edits in the child functions.php file?
Share Improve this question asked Jun 14, 2024 at 19:08 deneweydenewey 12 Answers
Reset to default 0You'll never have to copy anything from the parent theme to your child theme. In the case of CSS it would be wasteful, in the case of functions.php
it will likely cause errors due to duplicated function names. If your parent theme is badly written it may not enqueue its own stylesheet when it's not the active theme and you may have to work around that, for example by enqueueing the parent theme's stylesheet manually in your child theme's functions.php
:
add_action( 'wp_enqueue_scripts', 'wpse425666_enqueue_styles' );
function wpse425666_enqueue_styles() {
wp_enqueue_style(
'your-theme-parent-style',
get_parent_theme_file_uri( 'style.css' )
);
}
Note that this is just an example, we can't tell you whether this will be necessary because we don't know what your parent theme is and whether it's been coded properly to allow for child themes.
You shouldn't copy content of style.css
and functions.php
from parent.
The functions.php
file from the child theme will be loaded before the one from the parent theme. For a style.css
, it depends on the theme. The parent theme may load both style files or just one from the active theme. You can read more here and here.
本文标签: For a Child Themedo I duplicate the parent stylecss and then add my child css
版权声明:本文标题:For a Child Theme, do I duplicate the parent style.css and then add my child css? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303751a1931993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论