A child theme inherits all functionality and styling from DigiFlash while allowing you to make customizations that won’t be overwritten during theme updates. Child themes are essential for adding custom code, modifying templates, or extending DigiFlash functionality.
Child Theme File Structure
Create a new directory in wp-content/themes/ for your child theme. The minimum required structure is:
digiflash-child/
├── style.css
└── functions.php
```
For more advanced customizations, you can add:
```
digiflash-child/
├── style.css
├── functions.php
├── theme.json (optional)
├── templates/ (optional)
├── parts/ (optional)
└── patterns/ (optional)
Creating style.css
The style.css file is required and must include the theme header. Create this file in your child theme directory:
/*
Theme Name: DigiFlash Child
Theme URI: https://yoursite.com
Description: Child theme for DigiFlash
Author: Your Name
Author URI: https://yoursite.com
Template: digiflash
Version: 1.0.0
License: GNU GPL version 2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: digiflash-child
*/
The Template: digiflash line is critical – it tells WordPress which parent theme to use.
Creating functions.php
The functions.php file handles enqueueing the parent theme stylesheet and any custom functionality. Create this file:
<?php
/**
* DigiFlash Child Theme Functions
*/
// Enqueue parent and child theme styles
function digiflash_child_enqueue_styles() {
// Enqueue parent theme stylesheet
wp_enqueue_style(
'digiflash-parent-style',
get_template_directory_uri() . '/style.css',
array(),
wp_get_theme()->parent()->get('Version')
);
// Enqueue child theme stylesheet
wp_enqueue_style(
'digiflash-child-style',
get_stylesheet_uri(),
array('digiflash-parent-style'),
wp_get_theme()->get('Version')
);
}
add_action('wp_enqueue_scripts', 'digiflash_child_enqueue_styles');
Activating the Child Theme
- Upload the child theme folder to
wp-content/themes/ - Navigate to Appearance > Themes in WordPress admin
- Locate DigiFlash Child and click Activate
Overriding Templates
To customize a template, copy it from DigiFlash’s /templates directory to your child theme’s /templates directory with the same filename. For example:digiflash-child/templates/single.html
Overriding Template Parts
Copy template parts from /parts to your child theme:digiflash-child/parts/header.html
digiflash-child/parts/footer.html
Modify the copied files to customize headers or footers. Changes persist through parent theme updates.
Using theme.json in Child Themes
Create a theme.json file in your child theme to override specific settings from the parent theme. The child theme’s theme.json merges with the parent:
{
"version": 2,
"settings": {
"color": {
"palette": [
{
"slug": "primary",
"color": "#your-color",
"name": "Primary"
}
]
}
}
}
Only include settings you want to override – the rest inherit from DigiFlash.
Adding Custom Block Patterns
Create a /patterns directory in your child theme and add pattern files:
<?php
/**
* Title: Custom Hero
* Slug: digiflash-child/custom-hero
* Categories: hero
*/
?>
<!-- Block markup here -->
Register custom pattern categories in your child theme’s functions.php:
function digiflash_child_register_patterns() {
if (function_exists('register_block_pattern_category')) {
register_block_pattern_category(
'custom',
array(
'label' => __('Custom Patterns', 'digiflash-child'),
'description' => __('Custom patterns for your site', 'digiflash-child'),
)
);
}
}
add_action('init', 'digiflash_child_register_patterns');
Adding Custom Functions
Add any custom PHP functions to functions.php after the style enqueue function:
// Custom function example
function digiflash_child_custom_function() {
// Your code here
}
add_action('wp_footer', 'digiflash_child_custom_function');
All parent theme functions remain accessible in the child theme. You can override parent functions by checking if they exist first, then defining your own version.