HowTo

How to Use a Child Theme in WordPress (and Why)

Child Theme in WordPress – How to Use a Child Theme in WordPress (and Why)

In this guide: How to use a child theme in WordPress: what a child theme is, when you need one, how to create it, adding custom CSS and functions, and common mistakes.

You customize your WordPress theme — edit a template, add CSS, tweak a function — and everything looks perfect. Then the theme updates and all your changes disappear. A child theme prevents that.

What a child theme is

A child theme is a theme that inherits everything from another theme (the parent) while letting you override specific parts.

  • The parent theme provides the design, templates, and features.
  • The child theme contains only your customizations.
  • When the parent updates, your child theme stays untouched.

WordPress loads the child theme’s files first. If a file exists in the child theme, it’s used; if not, WordPress falls back to the parent.

When you need one

You need a child theme if you plan to:

  • Edit theme template files (like header.php, single.php, or block theme templates stored as files).
  • Add PHP functions specific to the theme’s presentation.
  • Add substantial custom CSS you want to manage in files.
  • Override theme parts in a way you’ll maintain long term.

You may not need one if you only:

  • Change settings in the Customizer or Site Editor (these are stored in the database, not theme files).
  • Add small CSS tweaks via Additional CSS or global styles.
  • Add functionality — that belongs in a plugin or a code snippets plugin, not a theme.

Block themes: changes made in the Site Editor are saved in the database, so they survive updates. However, a child theme is still useful if you want to version-control templates and theme.json changes in files.

Creating a child theme

A basic child theme needs just two files.

1. Create a folder in /wp-content/themes/, for example: astra-child (use the parent’s folder name plus -child).

2. Create style.css:

/*
 Theme Name:   Astra Child
 Template:     astra
 Version:      1.0.0
 Description:  Child theme for customizations
*/

The Template line must exactly match the parent theme’s folder name (not its display name).

3. Create functions.php to load styles (for classic themes):

<?php
add_action( 'wp_enqueue_scripts', function () {
    wp_enqueue_style(
        'child-style',
        get_stylesheet_uri(),
        array(),
        wp_get_theme()->get( 'Version' )
    );
} );

Many modern parent themes already load their own stylesheet correctly; check the parent theme’s documentation — some recommend also enqueuing the parent stylesheet explicitly.

4. Upload and activate: zip the folder and upload via Appearance → Themes → Add New → Upload, or upload via SFTP. Then activate the child theme.

Shortcut: many popular themes provide a ready-made child theme download, and there are plugins that generate child themes for you.

Important: after switching to a child theme, some Customizer settings may need to be re-applied or imported, since they’re stored per theme.

Adding custom CSS and functions

CSS: add rules to your child theme’s style.css:

.site-header {
  background: #0B0F14;
}
.button {
  border-radius: 10px;
}

Override templates: copy a template file from the parent (for example, footer.php) into the child theme and edit the copy.

Functions: add PHP to the child theme’s functions.php. Unlike templates, the child’s functions.php doesn’t replace the parent’s — both load (child first).

// Change excerpt length
add_filter( 'excerpt_length', fn() => 25 );

For block themes, you can add a theme.json in the child theme to override colors, typography, and spacing, and copy template files from the parent’s templates folder to customize them.

Common mistakes

  • Wrong Template name — must match the parent folder exactly, or the child theme appears broken.
  • Editing the parent theme directly — changes vanish on update.
  • Putting business functionality in the theme — contact forms, custom post types, or SEO features belong in plugins so they survive theme changes.
  • Copying too many templates — only copy files you actually change, otherwise you miss parent improvements.
  • Not testing after parent updates — occasionally a parent update changes template structure, so review overridden files.
  • Using the Theme File Editor on a live site — a PHP typo can crash your site. Edit via SFTP or on staging, with a backup ready.

Further reading: official WordPress documentation

Key Takeaways: Child Theme in WordPress

  • A child theme protects your customizations from theme updates.
  • You need one for template and code changes, not for settings.
  • It requires only style.css (with the correct Template line) and usually functions.php.
  • Keep functionality in plugins and only override what you need.
Z
zasma171

Writes for Hostreta about the topics covered in this article.

Comments (0)

Your email address will not be published. Required fields are marked *

Recent Comments

No comments to show.
Ad · AdSense
Ad space 300×250
Affiliate links
Tools we recommend
Protect Your Website with Automated Daily Backups
$2.09
Get it
the easiest way to manage all of your social media accounts
$29
Get it
Starter Website Get online, properly
$249
Get it
google workspace Business Starter
$3.75
Get it
Nord Vpn Cybersecurity. Built for Everyday Use
$8.99
Get it

We may earn a commission on purchases made through these links, at no extra cost to you.

Ad · AdSense
Ad space 300×600
Ad · AdSense
Ad space 300×600

$ top hosting picks

affiliate
★★★★★

NovaHost

$2.95/mo,renews at $9.95
  • Free SSL + domain, first year
  • 1-click WordPress install
  • 24/7 chat, sub-5-min response
get this deal →
affiliate link · we may earn a commission
★★★★★

CloudRoot

$4.50/mo,renews at $12.95
  • Built-in CDN + caching
  • Daily backups, 30-day retention
  • Staging environments included
get this deal →
affiliate link · we may earn a commission
★★★★★

ByteForge

$3.75/mo,renews at $10.95
  • NVMe storage on every plan
  • Unlimited bandwidth
  • Free migration from your old host
get this deal →
affiliate link · we may earn a commission

Never miss a new article

Join thousands of developers and builders getting a weekly digest of the best tech articles.