top of page
Writer's pictureFahad H

Working with Child Themes in WordPress

WordPress is the world’s most popular website builder and content management system. One reason for this is its potential for virtually endless customization, which makes it possible to develop many different kinds of websites from the WordPress core code and its multitude of free and premium plugins and themes.

It is possible to find a WordPress theme to suit just about every need, and users with a little coding experience can customize any theme even further by working with child themes, derivatives of a main or parent theme that can be altered in multiple ways without affecting the parent theme’s code and structure. Here’s an overview of how- and why- to use child themes for customizing the look and feel of your WordPress website.

How Do WordPress Themes Work?

The core WordPress code is a free and open source package of files that can be used to build a website and manage the content that populates the site. But that site needs a theme, a second set of code that overlays the source code and creates a template for defining the site’s look, style, and layout.

Themes can be installed from the WordPress theme directory or purchased and downloaded from a long and growing list of developers worldwide, and most of these offer some options for customization right from the site’s Admin dashboard. However, some users want more – and that means going directly to the theme’s code to make changes, which can cause serious problems when changes are made directly to the active theme.

Parent Themes and Theme Frameworks

When a theme’s default customization options just don’t suit a site’s particular needs, users with coding experience could simply alter or add instructions in the theme code, but that’s a risky proposition. If the theme’s developers upgrade the theme, any local customization you’ve done to your installed version of the theme would be lost.

To make local changes without altering the theme’s original code, WordPress makes it possible to create a new copy of the theme and make all changes there. This “child” theme can then be installed and activated on the site like any other theme, and the “parent’ theme’s code remains unaffected.

Just about any theme can serve as a parent theme for one or more child themes, but some themes are designed specifically to serve as a parent theme capable of creating multiple child themes. These theme frameworks, such as the well-known Genesis framework, provide the basic structures for developing new themes so that designers don’t need to develop every new theme from scratch.

A child theme has its own name and functions as a separate theme in your theme directory, but because it exists only as a modification of the parent theme, the parent theme must also be present in order for it to work.

Why Create a Child Theme?

Creating a child theme from an existing WordPress theme allows you to customize it any way you choose, but if the theme needs only fairly minor changes, you may not need to take this step. Small style tweaks such as changing fonts, colors and layouts can be added with the help of a number of plugins that allow users to make limited changes to the site’s CSS, or Cascading Style Sheets, without going through the process of creating a child theme.

On the other end of the spectrum, if the changes you’re planning amount to a complete overhaul of every aspect of the theme, it might be best to develop a new theme from scratch or adopt an existing theme that offers more of the features you want. In most cases, though, creating a child theme offers the flexibility of making custom adjustments to the theme’s appearance with the support of an existing theme framework.

Working with child themes can also provide plenty of opportunities to learn more about working with code and the programming languages used to create WordPress sites, themes, and plugins. The child themes you create can remain exclusive to your site, or you can license them and make them available to other users through the WordPress theme directory and a variety of theme marketplaces worldwide.

Creating a child theme requires some experience with HTML and CSS, and the ability to work with files and folders within your WordPress install, but you don’t need to be a seasoned developer to create the elements necessary to develop your own child theme from an existing WordPress theme.

Creating a Child Theme: The Basics

It is possible to create your child theme directly within your site’s wp-content/themes files, but web development experts recommend creating the necessary files locally before adding them to your site’s active WordPress theme files. This allows you the opportunity to make all the needed changes – or experiment with new options – with no risk of affecting any of the existing directories on your site.

To create a child theme, you need just one folder and two files. Create a new folder for the child theme and give it a name. It can be anything you choose, but site developers suggest simply designating it as a child of the existing parent theme, such as “[parent theme name]-child.” Add this folder to your site’s wp-content/themes file.

A theme’s appearance is dictated by its style sheets – one or more sets of code that establish the rules for every aspect of the site’s look, such as fonts and font sizes, colors, spacing, and the layout of elements on the page. To build a new style sheet for your child theme, create a new text file and label it “style.css.” Place it in the child theme’s folder. To make the new style sheet work properly, you’ll need to insert a bit of code called the Style Sheet Header, which is available from the WordPress Codex, a source for WordPress development. The Header adds required information, such as the new theme’s name, the name of the template, or parent theme, and licensing information.

Copy or import the parent theme’s style sheet to your new file, and make any changes you like to that version. In this way, the parent theme’s style sheets remain intact and changes will be reflected only in the new child theme. Enqueue the style sheet so that it loads after the parent’s style sheet.

The last file that a child theme needs is called “functions.php.” Create this file and add it to the child theme’s folder. Then paste in the requisite code from the WP Codex. This file allows you to add more functions and features to the new theme.

Once these files are installed correctly in the site’s wp-content/themes files, you should be able to navigate to the site’s installed themes and see the new child theme’s name. Activate it as you would any other theme, and it replaces the parent theme in your site’s Admin dashboard.

WordPress owes much of its popularity to its wide-open options for customization ranging from simple adjustments within a theme to making site-wide changes with child themes. This makes it possible for anyone to create the ideal WordPress theme for business and personal sites of all kinds.

0 views0 comments

Comments


bottom of page