Child themes let you change a WordPress site's look or features without changing the original theme. This keeps your changes safe when the original theme updates.
0
0
Child themes and overrides in Wordpress
Introduction
You want to change colors or fonts on your site but keep the original theme's style.
You want to add new features or layouts without breaking the original theme.
You want to fix a small problem in the theme without editing its files directly.
You want to experiment with design changes but keep the original theme intact.
You want to update the original theme safely without losing your custom changes.
Syntax
Wordpress
/* style.css in child theme folder */ /* Theme Name: My Child Theme Template: parent-theme-folder-name */ @import url("../parent-theme-folder-name/style.css"); /* Your custom styles here */
The Template line must exactly match the parent theme folder name.
Use @import to load the parent theme's styles before adding your own.
Examples
This child theme changes the background color but keeps everything else from the parent.
Wordpress
/* style.css in child theme */ /* Theme Name: Simple Child Template: twentytwentyone */ @import url("../twentytwentyone/style.css"); body { background-color: #f0f0f0; }
This method loads parent and child styles properly using WordPress functions instead of @import.
Wordpress
<?php // functions.php in child theme add_action('wp_enqueue_scripts', function() { wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style')); });
Sample Program
This child theme changes the link color to red while keeping all other styles and features from the parent theme.
Wordpress
/* style.css in child theme folder */ /* Theme Name: Custom Child Template: twentytwentyone */ @import url("../twentytwentyone/style.css"); /* Change link color */ a { color: #e63946; }
OutputSuccess
Important Notes
Always use a child theme to keep your changes safe during parent theme updates.
Do not edit parent theme files directly; your changes will be lost on update.
Use the functions.php in the child theme to add or override PHP functions safely.
Summary
Child themes let you customize a WordPress theme without changing the original files.
Use a style.css with a Template line to link to the parent theme.
Load parent styles properly using @import or wp_enqueue_style in functions.php.