Understanding WordPress Child Themes

in

~

by

aenz Avatar

A WordPress child theme inherits features, functionality, and style from its parent theme. It allows safe modification without directly changing the parent theme’s files.

What is a WordPress Parent Theme?

Technically, all themes except child themes are parent themes. They are complete themes that can be installed and activated in WordPress.

What is a WordPress Child Theme?

A WordPress child theme is a sub-theme that inherits all the features, functionality, and style of its parent theme.

WordPress child themes provide a secure way to modify and add customizations to a parent theme without directly altering its files.

Instead, you can override specific templates or files within the child theme, allowing for safe customization while preserving the parent theme’s core functionality.

I am a WordPress theme user, not a developer.

Some theme makers offer their own child themes. Why should I activate and use the child rather than the parent theme?

Using a child theme instead of the parent theme is a good practice in WordPress, whether developing a child theme with extensive modifications or just using it for minor changes to your website.

This approach safeguards any modifications you make, ensuring those changes persist through the parent theme updates.

What about WordPress Block Themes?

Whether you’re using a classic or block theme, using a child theme for modifications is a good practice.

WordPress Theme Hierarchy

The standard WordPress theme hierarchy has only two levels: parent and child.

However, when building or using block themes, there are other levels to what is displayed on the front end of a site (they are not a part of the theme layer):

  1. WordPress itself (default theme.json)
  2. Parent theme
  3. Child theme
  4. User customizations

The user customization layer functions as a “grandchild” theme but with the distinction that it stores changes in the database rather than the filesystem.

How to Create a WordPress Child Theme

If you use a WordPress block theme like Twenty Twenty-Four, as I do in the following example, you can use the Create Block Theme plugin to create a child theme of your current theme. You can also clone the theme, among other things.

Here’s a short video showing how.

Read this article to learn more about the plugin and how to create block themes without handling code.

To create manually a WordPress child theme for your parent theme, follow these steps:

Create a New Folder

Create a new folder for your child theme inside your WordPress installation’s wp-content/themes directory. Give it the name you like.

Create a Stylesheet (style.css)

WordPress requires that all themes include a style.css file.

The CSS file’s most crucial function is registering the theme with WordPress through configuration data at the top.

Many themes also use it to serve CSS to the front end and even the editor.

Inside your child theme folder, create a style.css file and then add the following code at the top of the file:

/*
Theme Name: aenz
Template: twentytwentyfour
*/

Customize the ‘Theme Name’ to your preference. The ‘Template’ should be the directory name of your parent theme. These are the minimum required fields to make the child theme work.

Load style.css

You may need to do this to ensure that any CSS code you write in ‘style.css’ is loaded.

Within your child theme folder, create a ‘functions.php’ file. This file will enqueue the parent and child theme stylesheets.

Add the following code:

function aenz_enqueue_styles() {
	wp_enqueue_style( 
		'aenz-style', 
		get_stylesheet_uri()
	);
}
add_action( 'wp_enqueue_scripts', 'aenz_enqueue_styles' );

Activate the Child Theme

Go to your WordPress admin dashboard and navigate to Appearance > Themes. Your newly created child theme should be listed.

My Conclusion

A child theme is a tool for theme developers and website owners. It provides a safe way to customize and extend the functionality of a WordPress theme, ensuring those changes persist through the parent theme updates.

Source: Child Themes – Theme Handbook | Developer.WordPress.org

Welcome to aenz! I’m Franco, and I’m learning web design and development. Here, I share my journey and insights into building a successful brand and business online. I design with Figma and develop websites with WordPress.

Newsletter

Subscribe to three monthly emails with my latest learnings, zero-cost resources, and tutorials.

    Keep Learning