WordPress child themes inherit parent theme functionality whilst enabling safe customisations surviving updates. Child themes contain only modifications and additions; parent themes provide core functionality. Professional WordPress development uses child themes separating client customisations from base themes ensuring update compatibility and maintainable code structures.
Child themes are WordPress themes inheriting templates, functions, and styles from parent themes. Child themes override specific parent elements whilst inheriting everything else automatically.
Parent theme updates don't overwrite child theme modifications. Update parent themes maintaining security and compatibility whilst preserving customisations safely.
Child themes require only two files minimum: style.css with parent theme declaration and functions.php enqueueing parent styles. Additional files override parent templates as needed.
Professional development uses child themes customising commercial themes. Avoid modifying parent themes directly preventing update conflicts.
Child themes enable experimenting safely. Test modifications in child themes without risking parent theme functionality.
Understanding child themes distinguishes professional from amateur WordPress development practices.
Child themes protect customisations during parent theme updates. Direct parent modifications disappear when themes update creating maintenance nightmares.
Update Safety: Parent theme updates deliver bug fixes, security patches, and new features. Child themes enable updates without losing customisations.
Organised Development: Separate customisations from base code. Clear separation improves maintainability and collaboration.
Efficient Customisation: Start with quality parent themes. Add only necessary modifications rather than building from scratch.
Risk Mitigation: Experiment safely. Broken child theme changes don't affect parent functionality enabling quick rollbacks.
Client Handoff: Clients update parent themes independently. Customisations remain protected enabling non-technical maintenance.
Child themes prove essential for commercial theme customisation. Never modify premium themes directly.
Child theme creation requires two essential files plus optional template overrides. Simple process enables powerful customisation capabilities.
Create Child Theme Directory:
Create folder in wp-content/themes/: parent-theme-child/
Create style.css:
/*
Theme Name: Parent Theme Child
Template: parent-theme
Description: Child theme for Parent Theme
Author: London Web Design
Author URI: https://londonweb.design/
Version: 1.0.0
Text Domain: parent-theme-child
*/
/* Custom styles below */
Template Field: Must exactly match parent theme directory name. WordPress uses this identifying parent.
Create functions.php:
<?php
/**
* Child theme functions
*/
// Enqueue parent and child styles
function parentchild_enqueue_styles() {
// Parent theme stylesheet
wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css'
);
// Child theme stylesheet
wp_enqueue_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array('parent-style'),
wp_get_theme()->get('Version')
);
}
add_action('wp_enqueue_scripts', 'parentchild_enqueue_styles');
Activate Child Theme:
Navigate to Appearance > Themes. Activate child theme. Parent theme provides functionality; child theme applies customisations.
Child theme creation takes minutes enabling hours of safe customisation.
Child theme stylesheets override parent styles. CSS specificity rules determine which styles apply when conflicts exist.
Adding Custom Styles:
Add styles to child theme style.css after header comments:
/* Customise header */
.site-header {
background-color: #333;
padding: 20px 0;
}
/* Modify navigation */
.main-navigation a {
color: #fff;
font-weight: 600;
}
/* Adjust footer */
.site-footer {
background-color: #222;
color: #ccc;
}
Overriding Parent Styles:
Use equal or higher specificity overriding parent declarations:
/* Parent has: .widget { margin: 10px; } */
/* Child overrides with equal specificity */
.widget {
margin: 20px;
}
/* Or increase specificity */
.sidebar .widget {
margin: 20px;
}
Organising Child Theme CSS:
Comment sections logically:
/* ==========================================================================
Header Styles
========================================================================== */
/* ==========================================================================
Content Styles
========================================================================== */
/* ==========================================================================
Footer Styles
========================================================================== */
Child theme styles load after parent styles. Later declarations override earlier ones given equal specificity.
Browser developer tools identify parent styles requiring override. Inspect elements revealing applied styles and selectors.
Combine style customisation with web design principles ensuring aesthetic quality.
Child themes override parent templates by copying files to child theme directories. Child theme versions take precedence over parent templates.
Template Override Process:
Example: Overriding header.php:
Copy parent-theme/header.php to parent-theme-child/header.php. Modify child version. WordPress uses child template automatically.
Example: Template Parts:
Override template parts maintaining directory structure:
parent-theme/template-parts/content.php
↓ Copy to ↓
parent-theme-child/template-parts/content.php
Selective Overrides:
Override only necessary templates. Unnecessary overrides complicate maintenance when parent templates improve.
Template Changes:
When parent templates change significantly, review child overrides. Outdated child templates miss parent improvements or security fixes.
Template overrides provide surgical customisation. Change specific templates without affecting remaining theme structure.
Child theme functions.php adds custom functionality without modifying parent themes. Functions execute after parent functions enabling extensions and overrides.
Adding Custom Functions:
<?php
// Enqueue scripts (shown earlier)
// Custom function
function parentchild_custom_excerpt_length($length) {
return 30; // words
}
add_filter('excerpt_length', 'parentchild_custom_excerpt_length');
// Custom post types
function parentchild_register_post_types() {
register_post_type('portfolio', array(
'public' => true,
'label' => 'Portfolio',
'supports' => array('title', 'editor', 'thumbnail'),
));
}
add_action('init', 'parentchild_register_post_types');
// Widget areas
function parentchild_widgets_init() {
register_sidebar(array(
'name' => 'Custom Sidebar',
'id' => 'custom-sidebar',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
));
}
add_action('widgets_init', 'parentchild_widgets_init');
Modifying Parent Functions:
Remove parent actions/filters then add modified versions:
// Remove parent function
remove_action('init', 'parent_function');
// Add replacement
function parentchild_replacement() {
// Custom functionality
}
add_action('init', 'parentchild_replacement');
Namespacing:
Prefix functions preventing conflicts: parentchild_ or clientname_.
Child theme functions extend parent capabilities. Add features without parent theme modifications.
Professional child theme development follows established patterns ensuring maintainable, efficient customisations.
Minimal Overrides: Override only necessary templates. Excessive overrides complicate maintenance and miss parent improvements.
Document Changes: Comment modifications explaining purposes and reasoning. Future developers (including yourself) benefit from documentation.
Version Control: Use Git tracking child theme changes. Version history enables rollbacks and change review.
Test Updates: Test parent theme updates on staging sites before production. Verify child theme compatibility before deploying updates.
Organised Structure: Maintain clean file organisation. Group related customisations logically.
Performance Consideration: Avoid unnecessary code. Efficient child themes don't slow sites through bloated customisations.
Security: Follow WordPress security standards. Child themes require same security vigilance as parent themes.
Backup Before Changes: Backup sites before significant child theme modifications. Safety nets enable confident experimentation.
Professional practices distinguish quality child theme development from amateur modifications.
Integrate best practices with comprehensive WordPress development standards.
Avoid common mistakes creating problematic child themes requiring corrections or rebuilds.
Incorrect Template Field: Template field must exactly match parent directory name. Incorrect values prevent child theme functionality.
Missing Parent Style Enqueue: Don't use @import for parent styles. Properly enqueue parent stylesheet in functions.php.
Modifying Parent Directly: Never modify parent themes. Always use child themes for customisations.
Overriding Too Much: Copying entire parent theme into child defeats purpose. Override only necessary files.
Outdated Overrides: Old template overrides miss parent security fixes. Review overrides when updating parents.
Breaking Parent Functions: Removing parent actions/filters without replacements breaks functionality. Ensure modifications maintain necessary features.
Ignoring Updates: Child themes don't eliminate update needs. Parent themes still require security updates.
Poor Organisation: Disorganised child themes become unmaintainable. Structure files logically from start.
Avoiding mistakes saves debugging time and prevents broken sites.
Child themes and theme frameworks serve different purposes though sometimes confused.
Child Themes:
Theme Frameworks:
Child themes work with any parent theme. Frameworks require framework-specific child themes.
Most businesses use child themes customising commercial themes. Frameworks suit developers building multiple sites or requiring architectural foundations.
Choose child themes for commercial theme customisation. Consider frameworks when building from scratch or developing multiple similar sites.
Thorough testing ensures child theme modifications function correctly without breaking parent functionality.
Testing Checklist:
Visual Testing:
Functionality Testing:
Performance Testing:
Update Testing:
Compatibility Testing:
Staging environments enable safe testing. Never test significant changes directly on production sites.
Professional testing prevents embarrassing bugs and ensures quality modifications.
Do I need child theme for minor CSS changes?
Small CSS modifications often work through WordPress Customizer's Additional CSS feature without child themes. However, child themes prove better for substantial customisations involving multiple CSS files, template modifications, or custom functions. Additional CSS disappears when changing themes; child themes provide portable customisations. For ongoing customisation or commercial projects, child themes prove worthwhile even for initially minor changes.
Will child themes slow my website?
Properly built child themes don't significantly impact performance. Child themes add one additional stylesheet and potentially template files. Performance impact proves negligible compared to benefits. However, poorly optimised child theme code, excessive database queries, or bloated custom functions slow sites. Efficient child theme development maintains parent theme performance. Combine child themes with WordPress speed optimisation ensuring optimal performance.
Can I have child theme of child theme?
Technically possible but strongly discouraged. Grand-child themes create complex inheritance chains complicating maintenance and debugging. WordPress doesn't officially support multi-level child themes. If needing extensive customisation beyond child theme capabilities, consider building standalone custom theme instead. Two-level inheritance (parent-child) represents maximum recommended depth for maintainability.
What happens if I delete parent theme?
Child themes require parent themes functioning. Deleting parent themes breaks child theme sites completely. WordPress displays errors when parent themes missing. Always maintain parent themes even when only using child themes. Parent theme updates remain necessary for security and compatibility. Child themes depend on parent functionality; they're extensions not replacements.
Can I use multiple child themes?
WordPress supports only one active theme at a time. Multiple child themes for single parent cannot run simultaneously. However, create multiple child themes for different purposes (e.g., testing variations) switching between them. Only one child theme activates at any moment. If needing multiple simultaneous customisations, incorporate all modifications into single child theme.
Should I update parent theme if child theme works?
Yes, always update parent themes despite working child themes. Parent updates address security vulnerabilities, bug fixes, and compatibility improvements. Security updates prove critical regardless of apparent functionality. Test updates on staging sites before production deployment. Child themes survive updates; that's their purpose. Neglecting parent updates creates security risks and compatibility issues with WordPress updates.
How do I know which files to override?
Override only files requiring modifications. Examine parent theme identifying which template or function needs changes. Use browser developer tools identifying CSS requiring override. Review parent theme code understanding which templates control specific outputs. Avoid blindly copying all parent files. Surgical overrides maintain easier updates and reduce maintenance complexity. When uncertain, start with style.css-only modifications before template overrides.
Related WordPress Development Topics:
Written by the WordPress Development Team at London Web Design, implementing child themes for London businesses since 2010.