How to Create a WordPress Child Theme Using WP-CLI

On this page
  1. What Is a Child Theme?
  2. Before You Begin
  3. Check the Parent Theme Name
  4. Create the Child Theme
  5. Activate the Child Theme
  6. Edit the Child Theme Files
  7. Test the Website
  8. Summary

A WordPress child theme allows you to customize an existing theme without modifying the original theme files. This is important because changes made directly in the parent theme may be lost during theme updates.

WP-CLI makes it possible to create a child theme quickly from the command line.

What Is a Child Theme?

A child theme is a theme that inherits the design and functionality of another theme, called the parent theme.

You can use a child theme to safely modify:

  • CSS styles
  • Template files
  • Theme functions
  • Layout elements

The parent theme can still be updated without overwriting your custom changes.

Before You Begin

You need:

  • SSH access to the server
  • WP-CLI installed
  • WordPress already installed
  • The parent theme already installed

Connect to your server via SSH and go to your WordPress installation directory:

cd public_html

The exact directory may differ depending on where WordPress is installed.

Check the Parent Theme Name

Before creating the child theme, check the installed themes:

wp theme list

Find the parent theme slug in the name column.

For example:

twentytwentyfour
astra
generatepress

You will need this slug in the next step.

Create the Child Theme

Use the following command:

wp scaffold child-theme my-child-theme --parent_theme=parent-theme-slug

Replace:

  • my-child-theme with the name of your child theme folder
  • parent-theme-slug with the actual parent theme slug

Example:

wp scaffold child-theme astra-child --parent_theme=astra

WP-CLI will create the child theme directory and the required files automatically.

Activate the Child Theme

After creating the child theme, activate it with:

wp theme activate astra-child

You can confirm that it is active by running:

wp theme list

Edit the Child Theme Files

The child theme will be created in:

wp-content/themes/astra-child/

You can edit files such as:

  • style.css
  • functions.php

Use style.css for custom CSS and functions.php for custom PHP functions.

Test the Website

After activating the child theme:

  • Open the website in your browser.
  • Check that the layout loads correctly.
  • Verify that custom styles are applied.
  • Test key pages and features.

If something looks broken, switch back to the parent theme and review the child theme files.

Summary

Creating a WordPress child theme with WP-CLI is a fast and safe way to customize a website without editing the parent theme directly. Use wp scaffold child-theme, activate the new theme, and add your custom changes inside the child theme directory.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.