Child Themes

Whenever you face the need to make customizations directly to your website’s core files, especially to the functions.php file ⚠️, it is recommended that you create a child theme for that purpose. Child themes can help isolate the code from the main site and preserve the changes you made even after a major WordPress upgrade.

Here’s a basic structure of a child theme:

child-theme-name/
├── style.css
└── functions.php

Create the style.css file:

/*
Theme Name:   Child Theme Name
Theme URI:    https://example.com/child-theme-name/
Description:  Child theme for Parent Theme Name.
Author:       Your Name
Author URI:   https://example.com
Template:     parent-theme-name // Replace with your parent theme's name
Version:      1.0.0
*/

/* Your custom CSS styles go here */

Create the functions.php file:

<?php
function child_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-theme-style',   
 get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-theme-style', get_stylesheet_directory_uri() . '/style.css', array(   
 'parent-theme-style' ) );
}

add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );

Explore these videos for insights and tutorials on Child theme. This section comprises 3 modules with a combined duration of 25 minutes.

Video ContentTime
Basics of Child Themes06:14
Overriding Parent Functionality Pt 111:57
Overriding Parent Functionality Pt 206:57

For more information on WordPress child themes, check out the Child Themes page from the Theme Developer Handbook.

Ideas to Explore:

  • How do you customize a parent theme using a child theme without directly modifying the parent theme’s files?
  • What are the key considerations when creating a child theme to ensure compatibility with future updates of the parent theme?
  • Is it possible to create a theme that does not require a parent theme, using only a child theme or custom theme structure?
  • How can you troubleshoot issues related to child themes not reflecting changes made to the parent theme?
  • How can a child theme be used to add new functionality to a WordPress site without modifying the core files of the parent theme?