Skip to content
Development

How to set up a WordPress child theme, and why

What a child theme is, when you need one, and how to create one for a classic or block theme without breaking updates or styles.

By WP24×7 engineers6 min readPublished September 17, 2020Updated November 29, 2026

At a glance

A guide to WordPress child themes: what they are, when you need one and when Additional CSS or a small plugin is enough. It gives the files for a classic theme and for a block theme, explains how to override templates and parent functions safely, lists what to check after a parent update, and includes a troubleshooting table.

Updated November 29, 2026 · For WordPress site owners and developers

  • For site owners and developers customizing a theme
  • Need one when you edit template files or add theme PHP
  • Not needed for CSS-only changes or theme options
  • Classic theme style.css with Template, plus functions.php
  • Block theme style.css with Template, optional theme.json
  • After parent updates compare any template files you copied

A child theme is a small theme that inherits everything from a parent theme, so you can change templates, styles and functions without editing the parent. Create one before you modify any theme file, because a parent theme update overwrites your edits.

Why use a child theme at all?

When the theme author releases an update, WordPress replaces the parent theme's folder. Anything you edited there is gone, and so is the security fix you wanted. A child theme keeps your changes in a separate folder, so you can update the parent safely.

What you wantUse
Only CSS changesAdditional CSS (Customizer) or Site Editor styles, stored in the database
Change settings or coloursThe theme's own options, no child theme
Edit template files, add theme PHP, register blocks or patternsA child theme
Add functionality unrelated to appearance, such as a custom post type or shortcodeA small plugin, so it works if you change theme
A child theme sits beside the parent and overrides only what you change

How do I create a child theme?

Take a backup first. Then connect by SFTP or your host's file manager. In wp-content/themes/, create a folder, for example mytheme-child. Use the parent's folder name plus -child so it is easy to recognise.

Inside the folder, create style.css:

/*
Theme Name: MyTheme Child
Template: mytheme
Version: 1.0.0
*/

Template must be the exact folder name of the parent, not its display name. Theme Name can be anything unique. Then create functions.php in the same folder to load the parent's styles:

<?php
add_action( 'wp_enqueue_scripts', function () {
	$parent = wp_get_theme( get_template() );
	wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array(), $parent->get( 'Version' ) );
	wp_enqueue_style(
		'child-style',
		get_stylesheet_uri(),
		array( 'parent-style' ),
		wp_get_theme()->get( 'Version' )
	);
} );

In Appearance, Themes, activate the child theme. Your site should look the same. If it looks unstyled, the parent stylesheet is not loading: some themes load their CSS from a different file or build step, so look at how the parent enqueues it. Some themes already enqueue their own stylesheet, and then the code above loads it twice. If the parent handle is already registered, depend on that handle instead of adding a new one.

How do I override a template file?

Copy the file from the parent into the child folder, keeping the same relative path, and edit the copy. WordPress uses the child's version when it exists. For example, copy single.php or template-parts/content.php.

  • Copy only what you change. Every copied file is something you must maintain.
  • Never copy functions.php. Both files load: the child's first, then the parent's. Add your own functions in the child, and use hooks and filters to alter parent behavior.
  • For WooCommerce templates, copy into your-child-theme/woocommerce/ and watch the template version notice in WooCommerce's status screen after updates.

A worked example: changing one template

Imagine a classic theme whose single post template shows the author name above the title, and you want it below.

  1. Find the file

    A search in the parent theme's folder for the_author or get_the_author points to template-parts/content-single.php.

  2. Copy it

    Put it in the child at template-parts/content-single.php, keeping the folder structure.

  3. Edit the copy

    Move the author line below the title.

  4. Reload a post

    If nothing changes, a caching plugin or a different template (for example a custom post type's template) is in use.

  5. Leave a note

    Write a comment saying what you changed and which parent version you copied it from.

That last step is cheap and saves the next person an hour. When the parent updates, compare against the version named in your comment.

How do I change a parent function safely?

Most well-built themes wrap functions in if ( ! function_exists( ... ) ), so a child can define its own version first. Others use filters and actions. Prefer, in this order: a filter, an action, a pluggable function, then a copied template. Never edit the parent. If you remove or replace something the parent adds, do it with remove_action or remove_filter at a later priority, after the parent has added it:

add_action( 'after_setup_theme', function () {
	remove_action( 'wp_head', 'parent_theme_custom_meta', 10 );
}, 20 );

The function name here is only an example; use the one your parent actually registers, which you can find by searching its code.

What do I check after a parent update?

  1. Read the changelog

    Look for template changes in the parent's notes.

  2. Compare copied templates

    Check each against the parent's new version and merge changes.

  3. Load key pages

    Home, a post, a page, search, and the cart and checkout if it is a store.

  4. Check errors

    Look at the PHP error log or turn on WP_DEBUG_LOG on a staging copy.

This is the maintenance step people skip, and it is why a child theme is a safety net rather than a guarantee. A care plan covers updates with testing, and WordPress development is the right route if the customization is large enough to deserve a proper custom theme.

Troubleshooting

SymptomLikely causeWhat to check
Child theme shown as "broken"Template value does not match the parent folderThe parent's exact folder name
Site looks unstyledParent stylesheet is not enqueuedHow the parent loads its CSS
Styles load twiceParent already enqueues itselfRemove your duplicate enqueue
Menus and widgets vanished after switchingSettings are stored per themeRe-assign menus and widget areas
A copied template shows old markupA caching layerPurge caches, reload
Fatal error after adding codePHP syntax mistakeDebug log; undo the last change

Should the code live in the child theme at all?

Appearance belongs in the theme and behaviour belongs in a plugin. If you find yourself adding a custom post type, a shortcode or an integration to the child's functions.php, move it to a small plugin. Then a future redesign does not make that feature disappear, and the code is easier to reuse and test.

What mistakes should I avoid?

Want a theme customized properly?

A developer reads your brief, today.

FAQ

Questions people ask

12 answers. Can't find yours? Ask an engineer.

Do I need a child theme if I only add custom CSS?

Not necessarily. Additional CSS in the Customizer or Site Editor is stored in the database and survives theme updates. Use a child theme when you change template files or add PHP.

Link to this answer
Should I use @import to load the parent stylesheet?

No. @import makes the browser fetch styles one after another and slows the page. Enqueue the parent stylesheet with wp_enqueue_style, or, for a block theme, let WordPress load it.

Link to this answer
What happens to my child theme when the parent updates?

Your child theme files are untouched. Check any template file you copied, because the parent's newer version may fix bugs or add features your copy lacks.

Link to this answer
What must the Template header contain?

The exact folder name of the parent theme, not its display name. A misspelled value makes WordPress report the parent as missing and the child as broken.

Link to this answer
Should I copy the parent's functions.php into the child?

No. Both files load, the child's first, then the parent's. Add your own functions in the child and use hooks and filters to change parent behavior.

Link to this answer
Where do WooCommerce template overrides go?

In a woocommerce folder inside your child theme. Watch the template version notice on WooCommerce's status screen after updates, because copied templates can fall behind.

Link to this answer
Do I need functions.php in a block theme child?

Usually not. A block theme child needs only style.css with the Template header. WordPress loads the parent's styles and theme.json, and the child can add its own theme.json to override settings.

Link to this answer
Why did my menus and widgets vanish after activating the child?

Menu locations and widget areas are stored per theme. Re-assign them after switching, and test on a staging copy before switching a live site.

Link to this answer
Where should custom post types and shortcodes go?

In a small plugin, not the child theme. Appearance belongs in the theme and behavior in a plugin, so a future redesign does not make the feature disappear.

Link to this answer
Why does my parent stylesheet load twice?

Some themes already enqueue their own stylesheet. If the parent handle is already registered, depend on that handle in the child instead of adding a new enqueue.

Link to this answer
Can I edit theme files in the dashboard editor?

It is risky, because a syntax error can take the site down with no undo. Disable it with DISALLOW_FILE_EDIT in wp-config.php and change code by SFTP or Git instead.

Link to this answer
Can WP24x7 build a custom theme if a child theme is not enough?

Yes. When the customization is large enough to deserve a proper custom theme, theme development is the right route. Post a project with what you need and a developer will scope it.

Link to this answer

Keep reading

Want an engineer on it?

Tell us what is wrong in plain words. A person reads it, today.