Skip to content
BeoHosting
BeoHosting
WordPress

Guide to WordPress Child Themes

BeoHosting Team··10 min read read
Guide to WordPress Child Themes

What a WordPress child theme is

A child theme in WordPress is a theme that inherits functionality, styles, and template files from another theme called the parent. A child theme lets you change the design and functionality of a site without directly modifying the parent theme's files. Why is that important? Because when you update the parent theme, all your changes to its files are wiped and reset to default.

Imagine this scenario: you bought a premium WordPress theme, customized the CSS styles, added custom functions in functions.php, and changed template files. A month later, the theme author releases an update with security patches. You update the theme and - all your customizations are gone. You have to redo everything from scratch. With a child theme, this problem doesn't exist because your changes are stored in separate files that aren't touched during updates.

Why use a child theme

There are several key reasons to use a child theme instead of modifying the parent theme directly.

Safe updates

This is the primary reason. WordPress themes are regularly updated with security patches, bug fixes, and new features. Without a child theme, you have two bad choices: update the theme and lose all customizations, or don't update the theme and expose the site to security vulnerabilities. With a child theme, you update the parent theme worry-free because your changes are safe in the child theme.

Code organization

A child theme clearly separates your customizations from the original theme code. When you look at the child theme files, you see exactly what you changed compared to the original design. This makes debugging, documentation, and collaboration with other developers easier. If something doesn't work properly, you can simply delete the file from the child theme and revert to the original parent theme behavior.

Learning and experimenting

A child theme is a safe space for learning WordPress development. You can experiment with CSS, PHP, and template files without fear of breaking the site. If something goes wrong, you deactivate the child theme and the site reverts to the original look with the parent theme. This is especially useful for beginners who are just learning WordPress development.

Creating a child theme step by step

Creating a child theme is a simple process that requires only two files. Here's a detailed guide.

Step 1: Create the directory

In the wp-content/themes/ directory create a new folder for the child theme. Access the files via cPanel File Manager or FTP. The naming convention is parent-theme-name-child. For example, if you use the "flavor" theme, create the folder "flavor-child". This isn't required but it makes it easier to identify the child theme. The folder name must be unique among all themes on the site.

Step 2: Create the style.css file

Create a style.css file in the child theme directory with the following header comment: Theme Name (required - the unique name of your child theme), Template (required - the parent theme directory name, exactly as the folder is named), Version, Description, and Author. The Template field is critical - it must exactly match the parent theme folder name. If the parent theme is in the flavor folder, Template must be flavor. An error in this field means the child theme won't work.

Step 3: Create the functions.php file

Create functions.php in the child theme and add a function that enqueues the parent theme's styles. This is necessary for the child theme to inherit the parent theme's design. Use wp_enqueue_style() inside a function hooked to the wp_enqueue_scripts action. Enqueue parent-style with get_template_directory_uri() for the path to the parent theme and child-style with get_stylesheet_directory_uri() for the path to the child theme, with parent-style as a dependency so it loads first.

Step 4: Activation

Go to the WordPress admin panel, Appearance → Themes, and activate your child theme. You should see an identical site as before - all styles and functionality of the parent theme. If the site looks completely different (no styles), check that functions.php correctly enqueued parent styles and that the Template header in style.css is correct.

Customizing the child theme

Now that you have a functional child theme, you can start with customizations.

CSS customizations

Add your CSS changes to the style.css file of the child theme. Because the child theme loads AFTER the parent theme, your styles take priority (the CSS cascade principle). For example, if you want to change the title color, add the rule in child style.css and it will override the style from the parent theme. Use browser Developer Tools (F12) to identify the exact CSS selectors you need to change.

Template override

WordPress uses a template hierarchy to determine which file to use for displaying a page. A child theme can override any template file from the parent theme by creating a file with the same name. For example, if you want to change the look of a single blog post, copy single.php from the parent theme to the child theme and modify it. WordPress will automatically use the version from the child theme. IMPORTANT: copy the whole file, not just the part you're changing, because the child theme file completely replaces the parent version.

Functions.php specifics

Unlike template files where the child theme replaces the parent, functions.php from the child theme is loaded BEFORE functions.php of the parent theme. That means both files are active at the same time. This is useful because you can add new functions without copying the entire functions.php of the parent theme. But be careful - if you define a function with the same name as in the parent theme (and the parent uses an if(!function_exists()) check), your version will take priority.

Adding new template files

In addition to overriding existing template files, a child theme can add completely new ones. For example, you can create a custom page template that doesn't exist in the parent theme. Add a PHP file with a Template Name comment at the top and it will be available as an option in the WordPress editor when you create a new page. This is a powerful way to add specific layouts for landing pages, portfolio pages, or other custom needs.

Advanced techniques

Removing parent actions and filters

Sometimes you want to remove functionality from the parent theme instead of adding new functionality. Use remove_action() and remove_filter() in the child theme's functions.php to remove hooks the parent theme has registered. This requires knowing the exact function name, hook, and priority from the parent theme. Review the parent theme's source code to find this information. Note: remove_action() must be called after the action is registered - use the after_setup_theme hook with a later priority.

WooCommerce template override

If you use WooCommerce, the child theme can override WooCommerce template files by creating a woocommerce/ directory inside the child theme. For example, to customize the product page look, copy content-single-product.php from wp-content/plugins/woocommerce/templates/ to wp-content/themes/your-child-theme/woocommerce/ and modify it. WooCommerce will automatically use your version.

Using a child theme with page builders

If you use Elementor, Divi, or another page builder, a child theme is still recommended. The page builder stores content in the database so it doesn't depend on template files, but CSS customizations, custom PHP functions, and header/footer modifications should be in the child theme. Most popular themes (Astra, GeneratePress, OceanWP) have official child themes available for download from the theme author's site.

Common mistakes and how to avoid them

  • Wrong Template header: Template must exactly match the parent theme directory name. Even a difference in upper/lower case can cause an issue.
  • Missing parent style enqueue: Without proper enqueueing, the child theme won't inherit the parent theme design and the site will look broken.
  • Copying too many files: Don't copy all files from the parent theme to the child theme. Copy ONLY the files you actually change. Too many copies means you won't receive updates from the parent theme for those files.
  • Forgetting the PHP tag: functions.php must start with a <?php tag. Without it, WordPress won't recognize the file as PHP and will ignore it.
  • Editing the child theme instead of the Customizer: For simple changes (colors, fonts, layout) use the WordPress Customizer, which stores settings in the database. Use the child theme for structural changes the Customizer doesn't cover.

Conclusion

WordPress child themes are an essential tool for anyone customizing the look or functionality of their site. They're created in 5 minutes (two files), protect your customizations from parent theme updates, and provide an organized way to manage custom code. Whether you change just a few CSS rules or build complex template overrides, always use a child theme. At BeoHosting, our support can help you create and configure a child theme for your WordPress site, so you can safely customize the design without fear of losing changes.

BeoHosting Team

10+ years of experience — Web hosting and infrastructure specialists

  • Web Hosting
  • WordPress Hosting
  • VPS
  • Dedicated Serveri
  • Domeni
  • SSL
  • cPanel
  • LiteSpeed
  • Linux administracija
  • DNS

Last updated: