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 1
Add a comment  | 

2 Answers 2

Reset to default 0

You'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