When building commercial websites or customizing an existing WordPress theme, the most dangerous mistake a developer can make is directly modifying the parent theme's style.css or functions.php. When the theme creator releases a security or feature update, WordPress overwrites all parent files — instantly deleting every custom edit and line of code you wrote. The industry-standard solution is creating a Child Theme.
A Child Theme inherits all the functionality, styling, and templates of its Parent Theme. When a visitor requests a page, WordPress loads the child theme's styles and functions first. If a specific template file (like header.php or single.php) exists in the child theme, WordPress executes the child version; otherwise, it falls back to the parent version.
Let us create a production-ready child theme for the popular Astra parent theme. Follow these three steps:
Inside your WordPress directory, navigate to /wp-content/themes/ and create a new directory named after your parent theme with -child appended:
/wp-content/themes/astra-child/
Create a file named style.css inside /wp-content/themes/astra-child/ and insert the required header comment. The Template: declaration is case-sensitive and MUST match the parent theme's directory name exactly:
/*
Theme Name: Astra Child (Veewom)
Theme URI: https://veewom.com/wordpress/
Description: Custom High-Performance Child Theme for Astra
Author: Veewom Web Development Team
Author URI: https://veewom.com
Template: astra
Version: 1.0.0
Text Domain: astra-child
*/
/* Custom CSS Enhancements Below */
:root {
--vee-brand-orange: #ff6600;
}
.site-title a {
color: var(--vee-brand-orange) !important;
font-weight: 800;
}
Create a file named functions.php inside /wp-content/themes/astra-child/. Never use @import inside CSS, as it blocks parallel browser downloads. Instead, use the official WordPress wp_enqueue_scripts action hook:
<?php
/**
* Astra Child Theme functions and definitions
*/
add_action('wp_enqueue_scripts', 'veewom_enqueue_child_styles');
function veewom_enqueue_child_styles() {
// 1. Enqueue Parent Theme Stylesheet
wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css'
);
// 2. Enqueue Child Theme Stylesheet with dependency on parent
wp_enqueue_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style'),
wp_get_theme()->get('Version')
);
}
?>
This distinction is one of the most frequently failed questions on developer job interviews:
| PHP Core Function | Resolves Directory Path To: | Primary Usage |
|---|---|---|
get_template_directory_uri() |
Always points to the Parent Theme directory. | Loading parent theme core assets and templates. |
get_stylesheet_directory_uri() |
Points to the active Child Theme directory. | Loading child theme custom CSS, JavaScript, and custom images. |
To modify a template file like footer.php: copy footer.php from the parent theme directory and paste it directly into your /astra-child/ folder. Edit the child copy to add your custom copyright links or analytics scripts. WordPress will now automatically serve your modified child template while leaving the parent file pristine!
In viva exams: "Does the child theme's functions.php replace the parent theme's functions.php?" NO! Unlike template files (which override and replace the parent), the child theme's functions.php runs IN ADDITION to the parent's, and it executes BEFORE the parent theme's functions.php. This allows child themes to override pluggable parent functions before the parent registers them!
Expand your CMS mastery by studying these tightly integrated WordPress development topics:
Choose responsive, accessible, and fast parent themes.
Deep dive into functions.php, wp_enqueue_scripts, and template files.
Hook into parent themes cleanly using PHP callback functions.
Override parent template files in child themes with zero risk.