> For the complete documentation index, see [llms.txt](https://learn.sitecove.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.sitecove.com/how-to-guides/content-management-systems-cms/themes-templates-and-customization/creating-child-themes-for-safe-customization.md).

# Creating Child Themes for Safe Customization

A child theme allows you to customize a CMS theme without modifying the original (parent) theme files. This ensures that updates to the parent theme do not overwrite your changes, making it the safest way to customize a theme.\
This guide covers how to create a child theme for **WordPress**, **Joomla**, and **Drupal**, along with best practices for theme customization.

**Why Use a Child Theme?**

* **Preserves Customizations** – Updates to the parent theme won’t erase your changes.
* **Ensures Website Security** – Reduces risks of breaking the website with modifications.
* **Enhances Maintainability** – Organizes custom code separately for easy debugging.
* **Allows Future Updates** – Parent theme updates bring new features and security patches without affecting customizations.

**Pro Tip**: A child theme is essential for long-term theme customization without losing updates.

***

#### How a Child Theme Works

A child theme inherits the styles, layouts, and functionality of a parent theme while allowing independent modifications.

* **Parent Theme** – The original theme that provides core design and functionality.
* **Child Theme** – A separate theme that overrides or extends the parent theme’s styles and features.

***

#### Creating a Child Theme in WordPress

**Step 1: Create a Child Theme Folder**

1. Access your website files via FTP or File Manager.
2. Navigate to **/wp-content/themes/**.
3. Create a new folder named **yourtheme-child** (replace "yourtheme" with the parent theme name).

**Step 2: Create the style.css File**

1. Inside the child theme folder, create a file named **style.css**.
2. Add the following code:

```css
/*
Theme Name: YourTheme Child
Template: yourtheme
Version: 1.0
Description: A child theme for YourTheme
Author: Your Name
*/
```

3. Save the file.

**Step 3: Create the functions.php File**

1. In the child theme folder, create a file named **functions.php**.
2. Add the following PHP code to inherit styles from the parent theme:

```php
<?php
function yourtheme_enqueue_styles() {
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'yourtheme_enqueue_styles');
?>
```

3. Save the file.

**Step 4: Activate the Child Theme**

1. Log in to WordPress Admin Panel (**yourdomain.com/wp-admin**).
2. Navigate to **Appearance > Themes**.
3. Locate your child theme and click **Activate**.

**Pro Tip**: The child theme will now use the parent theme’s design but allows for modifications without risk.

***

#### Creating a Child Template in Joomla

Joomla does not have an automatic child theme system, but you can override a template safely.

**Step 1: Create an Override Folder**

1. Navigate to **/templates/yourtemplate/html/**.
2. Create a subfolder with the same name as the template file you want to override.
3. Copy the original template files into this new folder.

**Step 2: Modify Template Files**

1. Edit your copied files to customize styles and layouts.
2. Joomla will automatically load the overridden files from your custom folder instead of the parent template.

**Pro Tip**: Use Joomla’s Template Manager to preview overrides before applying them.

***

#### Creating a Sub-Theme in Drupal

In Drupal, a sub-theme functions like a child theme, inheriting the parent theme’s styles and structure.

**Step 1: Create a Sub-Theme Folder**

1. Navigate to **/themes/custom/**.
2. Create a new folder named **yourtheme\_sub**.

**Step 2: Create the .info.yml File**

1. Inside the sub-theme folder, create a **yourtheme\_sub.info.yml** file.
2. Add the following:

```yml
name: 'YourTheme Sub'
type: theme
base theme: yourtheme
version: 1.0
description: 'A sub-theme of YourTheme'
core_version_requirement: ^9 || ^10
```

3. Save the file.

**Step 3: Activate the Sub-Theme**

1. Log in to Drupal Admin Panel.
2. Navigate to **Appearance**.
3. Locate your sub-theme and click **Set as Default**.

**Pro Tip**: Use **Twig templates** in Drupal to override and customize theme files safely.

***

#### Best Practices for Child Themes

* **Keep Parent Theme Updated** – Regularly update the parent theme for security fixes.
* **Use a Custom CSS File** – Store modifications in the child theme’s **style.css**.
* **Override Templates Carefully** – Only modify necessary template files.
* **Test in a Staging Environment** – Avoid direct changes to the live site.
* **Document Changes** – Keep notes on modifications for future reference.

**Pro Tip**: If using custom PHP functions, always test on a staging site before deploying live.

***

#### Summary: Steps to Create a Child Theme

* Create a child theme or override folder.
* Add a **style.css** file to define the child theme.
* Use **functions.php** (WordPress) or **.info.yml** (Drupal) for settings.
* Modify template files safely to avoid breaking the layout.
* Activate the child theme from the CMS admin panel.
* Test customizations in a staging environment.
