In WordPress website development and theme customization, usingChild Theme This is the officially recommended best practice. By using child themes, you can freely adjust styles and functionality without modifying the parent theme's source code, preventing custom content from being lost when the parent theme is updated. However, many users are unaware of this when performing the operation. Which content must be written in style.css and functions.php?This article will focus on this core theme, emphasizing the essential content, recommended writing practices, and common pitfalls for these two key files within the child theme. It aims to help you correctly create and utilize child themes.

1. What is a WordPress child theme?
1. Definition of Child Themes
subthemeanThemes that depend on parent themes to runIt can inherit the parent theme's:
- Template files (such as header.php, single.php)
- Style Sheet (CSS)
- Function Logic (Code in functions.php)
At the same time, it allows you toOverride or extend in the child themeThis content.
![Image[2] - WordPress Child Theme Must-Read: One Mistake in style.css or functions.php and Your Website Efforts Are Wasted](https://www.361sale.com/wp-content/uploads/2025/12/20251218142141930-image.png)
2. Why use child themes?
Directly modifying the parent theme files will cause the following issues:
- After updating the parent theme, all modifications were lost.
- Not conducive to maintenance and debugging
- Prone to causing compatibility issues
while usingsubthemeThe advantage lies in:
- The parent theme can be safely updated at any time.
- All custom content is centralized in the child theme.
- More compliant with WordPress official development standards
Whenever you plan to modify the theme, you should use a child theme.
![Image[3] - WordPress Child Theme Must-See: One Mistake in style.css or functions.php, and Your Website Efforts Are Wasted](https://www.361sale.com/wp-content/uploads/2025/12/20251218142035111-image.png)
II. Minimum Usable Structure of Child Themes
A child theme that can be properly recognized and activated by WordPress,Theoretically, only one file is required.::
your-child-theme/ └── style.css
However, in actual development,Almost all of them will use functions.php simultaneously.::
your-child-theme/ ├── style.css └── functions.php
The reason is:
- Should the parent theme be loaded?typedepends on the implementation of the parent theme itself
- To ensure compatibility and the order in which styles are loaded, style management is typically handled within the child theme.
- Whenever any functionality needs to be added, functions.php must be used.
| filename | Is it necessary? | primary role |
|---|---|---|
| style.css | be | Declare child theme identity, write CSS |
| functions.php | No (strongly recommended) | Control style loading and add functionality |
- Without style.css, the child theme cannot be recognized.
- Whether functions.php is required depends on the parent theme and actual needs.
- In the vast majority of projects, both files are used simultaneously.
III. What must be included in the child theme's style.css?
1. The core function of style.css
In the child theme,style.css There are two main functions:
- Declare to WordPress that this is athematic
- Store the child theme's own CSS styles
Among them.The subject declaration information is required.Even if you don't write any CSS for now.
![Image[4] - WordPress Child Theme Must-See: One Mistake in style.css or functions.php and Your Website Efforts Are Wasted](https://www.361sale.com/wp-content/uploads/2025/12/20251218142359568-image.png)
2. Required theme header information in style.css
WordPress via style.css Use the comments at the top of the document to identify the subject.
Minimal Required Writing
/* Theme Name: My Child Theme Template: parent-theme-folder */
Theme Name and Template are child themes.
- Theme NameThe name of the child theme displayed in the WordPress admin panel. It can be customized but must be unique.
- TemplateFolder name of the parent theme (not the theme display name). If this field is entered incorrectly, the child theme will not function properly.
3. Recommended Complete Theme Header Information (Best Practice)
While these fields are not all required, they are highly valuable for tutorial websites, team projects, and long-term maintenance.
/* Theme Name: My Child Theme Theme URI: https://example.com/my-child-theme Description: A child theme developed based on the XX parent theme Author: Your Name Author URI: https://example.com Template: parent-theme-folder Version: 1.0.0 */
The functions of each field are as follows:
- Theme URIURL of the theme introduction or description page (optional)
- DescriptionBrief description of the subtopic for management and identification purposes.
- Author: Theme Author Name
- Author URIAuthor's homepage or company website address
- VersionChild theme version number, for easier maintenance and updates later on.
4. Write styles in style.css
Below the theme header information, you can directly write CSS:
body { background-color: ##f5f5f5; }
Something to keep in mind:
- Child theme's style.css Will not automatically load parent theme styles
- Whether the parent theme's styles take effect depends on whether the parent theme has correctly enqueued the style sheet.
5. Practices to Avoid in style.css
The following practices are no longer recommended:
- utilization
@importIntroducing parent theme styles - Writing PHP code in style.css
Example of an error:
@import url("../parent-theme/style.css");
This approach may impact performance and potentially cause issues with the loading order of styles.
4. What must be included in the child theme's functions.php file?
1. Description of the Purpose of functions.php
subtheme functions.php For use in:
- Managing the loading order of parent and child theme styles
- Add or modify theme features
- Overrides behavior added via hooks in the parent theme
It is important to clarify that:
2. Is functions.php absolutely necessary?
Technically speaking:
- If the parent theme has already loaded the styles correctly
- And you don't need to add any features.
Child themes can function properly even without a functions.php file.
However, in actual projects, to ensure compatibility and controllability,It is still generally recommended to create a functions.php file.The
| take | Is it necessary? |
|---|---|
| Only activate the child theme without modifying any content. | Not necessarily |
| Control the loading order of styles | need |
| Add any feature | necessarily |
| Business / Long-term Projects | urge |
3. The most common and safest approach in functions.php: Loading styles
Below is one of the officially recommended and most compatible approaches:
<?php add_action( 'wp_enqueue_scripts', 'my_child_theme_enqueue_styles' ); function my_child_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) ); }
Description:
get_template_directory_uri()Return to Parent Topic Pathget_stylesheet_uri()Return to the child theme's style.css path- Ensure correct loading order through dependencies
Before use,It is recommended to review the functions.php file of the parent theme.Confirm the location and loading method of its style sheet.
![Image [5] - WordPress Child Theme Must-See: One Mistake in style.css or functions.php, and Your Website Is Wasted](https://www.361sale.com/wp-content/uploads/2025/12/20251218144940753-image.png)
4. Common Extension Usage in functions.php
Add Theme Support
add_theme_support( 'post-thumbnails' ); add_theme_support( 'title-tag' );
Register Navigation Menu
register_nav_menus( array( 'main-menu' => 'Main Navigation Menu', ) );
Include other functionality files from the child theme
require_once get_stylesheet_directory() . '/inc/custom-functions.php';
5. Notes on functions.php
- Function names should remain unique and avoid conflicts with parentthematicor plugin conflicts
- In a pure PHP file,Recommended: Omit PHP terminatorto avoid output errors
![Image [6] - WordPress Child Theme Must-See: One Mistake in style.css or functions.php, and Your Website Efforts Are Wasted](https://www.361sale.com/wp-content/uploads/2025/12/20251218143634784-image.png)
V. Fully Functional Child Theme Example
style.css Example
/* Theme Name: My Child Theme Template: twentytwentyfour Version: 1.0.0 */ body { font-family: Arial, sans-serif; }
functions.php Example
<?php add_action( 'wp_enqueue_scripts', 'my_child_theme_enqueue_styles' ); function my_child_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) ); }
Link to this article:https://www.361sale.com/en/83348The article is copyrighted and must be reproduced with attribution.





















![Emoji[wozuimei]-Photonflux.com | Professional WordPress repair service, worldwide, rapid response](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![Emoticon[baoquan] - Photon Wave Network | Professional WordPress Repair Services, Worldwide Coverage, Rapid Response](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments