Creating a WordPress Child Theme

Have you ever edited CSS or added code directly to a theme's functions.php? If so, you have probably encountered this painful experience: theme updates wipe out all your customizations. Hours of CSS work gone in an instant the moment you click "Update."

A child theme is the correct, WordPress-standard solution to this problem. This guide explains what a child theme is, how it works, and how to create one from scratch — manually or with a plugin.

Never edit the parent theme directly. Any CSS or PHP changes made to the parent theme files will be overwritten the next time the theme updates. All your work vanishes immediately with no way to recover it.

What Is a WordPress Child Theme?

A child theme is a sub-theme that inherits everything from a parent theme but stores your customizations in its own separate files. This means all your changes are preserved when the parent theme updates, because the update only touches the parent theme's files — never your child theme.

How it works: WordPress loads the child theme first. If it cannot find a requested file in the child theme, it falls back to the parent theme. This lets you override only the parts you need without copying the entire theme.

Why You Must Create a Child Theme Before Any Customization

There are three core reasons:

Child Theme File Structure

A child theme requires a minimum of two files in a new folder inside /wp-content/themes/:

/wp-content/themes/
  my-parent-theme/          ← Parent Theme (do not edit)
  my-parent-theme-child/    ← Our Child Theme
    style.css               ← Required (Header + Custom CSS)
    functions.php           ← Recommended (Enqueue Parent CSS)

Creating a Child Theme Manually

Step 1: Create a New Folder

Using DirectAdmin File Manager or FTP, create a new folder inside wp-content/themes/. Name it something like twentytwentyfive-child (if your parent theme is Twenty Twenty-Five).

Step 2: Create style.css

Create a file called style.css in the new folder with this content:

/*
Theme Name: Twenty Twenty-Five Child
Template: twentytwentyfive
Description: Child theme of Twenty Twenty-Five
Author: Your Name
Version: 1.0
*/

/* Add your custom CSS here */

The most important line is Template: — it must exactly match the parent theme's folder name, including capitalization.

Step 3: Create functions.php

Create a functions.php file in the child theme folder to correctly enqueue the parent theme's stylesheet before the child's:

<?php
add_action( 'wp_enqueue_scripts', 'my_child_theme_enqueue_styles' );
function my_child_theme_enqueue_styles() {
    // Load Parent Theme stylesheet
    wp_enqueue_style(
        'parent-style',
        get_template_directory_uri() . '/style.css'
    );
    // Load Child Theme stylesheet (overrides parent)
    wp_enqueue_style(
        'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( 'parent-style' )
    );
}

Note: Many modern themes (Block themes using theme.json) load CSS differently. Some do not require manual wp_enqueue_style for the parent. Always check the theme's documentation to confirm the correct approach.

Activating the Child Theme

  1. Go to WordPress Admin → Appearance → Themes
  2. Your new child theme will appear in the list
  3. Click Activate on the child theme
  4. Your site looks identical — the child theme inherits everything from the parent

Creating a Child Theme with a Plugin (Child Theme Configurator)

If you prefer not to create files manually, a plugin can handle everything automatically.

Using Child Theme Configurator

  1. Install the free plugin Child Theme Configurator (400,000+ active installs)
  2. Go to Tools → Child Theme Configurator
  3. Select the parent theme you want to use
  4. Name the child theme and set options
  5. Click Create Child Theme
  6. The plugin creates the folder, style.css, and functions.php automatically, then activates the child theme immediately

Adding Custom CSS to Your Child Theme

There are two ways to add custom CSS:

Method 1: Edit style.css Directly

Open style.css in your child theme and add CSS after the comment header:

/* Custom CSS */
.site-header {
    background-color: #059669;
}
.entry-title {
    font-size: 2rem;
    font-weight: 700;
}

Method 2: WordPress Customizer

Go to Appearance → Customize → Additional CSS. This is more convenient but stores CSS in the database rather than in the child theme file.

Overriding Parent Theme Template Files

To change a page layout — for example, the single post template — copy the template file from the parent theme into your child theme folder and edit it there.

# Example: Override Single Post Template
# Copy from parent:
/wp-content/themes/twentytwentyfive/single.php

# Place in child theme:
/wp-content/themes/twentytwentyfive-child/single.php

# Edit single.php in the child theme as needed
# WordPress uses the child theme version automatically

Key rule: Only override files you actually need to change — not the entire theme. Copying everything defeats the purpose of a child theme and you lose the benefit of parent theme updates.

Adding Functions to Child Theme functions.php

The child theme's functions.php runs alongside the parent's — it does not replace it. You can safely add hooks, filters, and custom functions:

<?php
// Add custom analytics script
add_action( 'wp_head', 'my_custom_analytics' );
function my_custom_analytics() {
    // Insert analytics or any custom script
}

// Remove sidebar from single posts
add_filter( 'theme_mod_single_sidebar', '__return_false' );

// Register a custom post type
add_action( 'init', 'register_my_custom_post_type' );
function register_my_custom_post_type() {
    // ...
}

Using theme.json in a Child Theme (Block Themes)

Since WordPress 5.8, Full Site Editing (FSE) has changed how themes control styles and layouts. Block themes such as Twenty Twenty-Three, Twenty Twenty-Four, and Twenty Twenty-Five use a theme.json file instead of traditional CSS. This means child themes for block-based parents work slightly differently from classic child themes.

In a block theme child theme, you can create your own theme.json to override values defined in the parent. WordPress automatically merges the two files — your child theme values always win. A common use case is changing the site's primary color and typography:

{
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "color": {
      "palette": [
        { "name": "Primary",    "slug": "primary",    "color": "#059669" },
        { "name": "Background", "slug": "background", "color": "#f0fdf4" }
      ]
    },
    "typography": {
      "fontSizes": [
        { "name": "Small",  "slug": "small",  "size": "14px" },
        { "name": "Normal", "slug": "normal", "size": "16px" },
        { "name": "Large",  "slug": "large",  "size": "20px" }
      ]
    }
  }
}

The advantage of theme.json overrides is that the Block Editor immediately reflects your custom colors and fonts in the editing interface — keeping the editor and the live site in sync without writing long CSS selectors.

Note: If the parent is a block theme using theme.json, manually enqueueing the parent stylesheet in functions.php may be unnecessary — and could even cause styles to load twice. Always check the parent theme's documentation to confirm the correct approach for child themes.

Comparing Child Theme Creation Methods: Manual, Plugin, and WP-CLI

There are three main ways to create a child theme. Each suits a different situation:

Method Best for Advantages Watch out for
Manual (style.css + functions.php) Developers who want full control No extra plugins; you understand the structure Easy to mistype the Template header or enqueue order
Plugin (Child Theme Configurator) Non-technical users One-click setup; GUI options; no typos Requires installing a plugin; may miss block theme nuances
WP-CLI Developers with SSH access Fastest; scriptable; repeatable across many sites Requires WP-CLI and SSH on your hosting server

For users on shared hosting without SSH access, the manual method via DirectAdmin File Manager or FTP is perfectly practical. Create just two files and you are ready to go. Using WP-CLI, the equivalent single command is:

wp scaffold child-theme twentytwentyfive-child --parent_theme=twentytwentyfive --activate

Common Mistakes and How to Fix Them

Child themes are straightforward to set up, but there are a handful of recurring pitfalls worth knowing before you start:

Debug tip: If the site breaks after activating your child theme, open a private/incognito browser window and go to Appearance → Themes to deactivate the child theme. If the site returns to normal, the issue is in your child theme files — not the server or parent theme.

Backing Up and Maintaining Your Child Theme Long-Term

Your child theme folder holds every customization you have ever made to the site. Losing it — through a failed hosting migration, accidental deletion, or server failure — means losing all your work. Follow these practices to keep it safe:

Bottom line: A child theme requires only two files to get started but provides long-term protection that every WordPress site deserves. If your site is currently running without a child theme, create one now — before the next theme update wipes out your hard work.

WordPress Hosting with Full File Access — from 500 THB/year

AsiaGB Hosting fully supports WordPress child themes with DirectAdmin, SSD storage, free SSL, File Manager, and FTP access. Starting at 500 THB/year with no hidden fees.

View Hosting Plans →