Child theme
A Child Theme in WordPress is a theme that inherits the design, features, and functionality of another theme – called the parent theme – while allowing you to safely customize and extend it without modifying the parent theme directly.
Why Use a Child Theme?
Modifying a parent theme directly means your changes can be overwritten during updates. A child theme protects your customizations, making them upgrade-safe.
What a Child Theme Includes
At minimum, a child theme contains:
style.css– with a required comment block to define the theme and point to its parent.functions.php– to enqueue styles or add theme-specific PHP code.- (Optional) Template files – like
header.php,single.php, orpage.phpif you want to override or extend them.
Example: style.css for a Child Theme
/*
Theme Name: My Custom Child Theme
Template: twentytwentytwo
Version: 1.0
*/
Templatemust exactly match the folder name of the parent theme.
Example: Enqueueing the Parent Styles in functions.php
<?php
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles');
function my_theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
}
When to Use a Child Theme
- You want to tweak templates or PHP logic.
- You need to add custom functions or filters.
- You’re building on top of a framework or premium theme that gets updated regularly.
When Not to Use One
- If your changes are purely CSS and minimal, you can often use the Customizer or a custom CSS plugin.
- If you’re building an entirely new design from scratch, a custom theme may be better.
Summary
| Feature | Description |
|---|---|
| Purpose | Safe customization of a parent theme |
| Inherits | Styles and templates from parent |
| Created with | style.css, functions.php |
| Benefit | Update-safe, modular customization |