Child Theme Authoring: Introduction
This guide provides an overview of what the strengths and limitations of child themes are, how to go about building one for Layers, and how to add or remove functionality the right way. The result should be a clean, WordPress-compliant, dream-to-support theme for you or your client!
What is a Child Theme?
A child theme is jut like any other theme except it is able to inherit all of the functionality and front-end structure from Layers (the “parent”) .
There are a few reasons why you would want to use a child theme:
- If you modify Layers directly, you or your client will not be able to update it without losing the changes
- Child themes greatly speed up development time.
- Your child theme is essentially a self-contained set of changes which you are in a better position to track and manage.
- Your changes may only require 100 lines of code which can be organized in one place, whereas modifying the original disperses your changes throughout 1000 lines of code.
- Supporting 100 lines is much easier than 1000 – If you modify Layers, it becomes a derivative that you are responsible for supporting and maintaining.
- Using a child theme is a better way to to learn about WordPress theme development.
When to Use a Child Theme
The division between themes and plugins in WordPress has been a bit blurry for a long time, as both can introduce new functionality to a WordPress install.
You need a Child Theme when:
- You want to re-style a theme without or beyond what the WordPress customizer controls or other plugins allow you to do,
- You want to add a bit of code to a specific place (such as a search field in the header) or
- You want to add custom page templates
When you need to build an Extension (plugin):
- You want to add Custom Post Types
- You want to add Layers Builder Widgets
Child themes are for presentation, whereas extensions are for extending functionality.
If you just want to easily package and transfer Layers Page Builder Presets and CSS, you can do that most easily with a Style Kit and do not need a Child Theme. This is the best option for non-developers.
Theme vs Extension vs Style Kit
- Style Kit: Collection of presets generated from the Layers Customizer. Style Kits include the page builder widget setup, options and color settings, along with any internal assets required such as fonts or icons.
- Child Theme: Used when a style kit is not enough and usually includes multiple stylesheets, additional scripts and a functions file defining custom actions and filters.
- Extension: Used to introduce totally new functionality to Layers sites, including custom post types and their page templates.
This guide uses standard techniques for front-end development that require you to have a basic understanding of CSS and PHP . We reference several WordPress hooks, functions and template tags that can be found on the WordPress Codex, as well as several Layers hooks and functions which are linked directly to our Theme API reference. We recommend the following resources if you are just starting out:
- CSS Tricks
- Flexbox Froggy, interactive way to learn CSS Flex
- Learning PHP Fast and Easy
- WordPress Codex (view standard documentation or search for any hook at the top of the page)
- Layers Reference
- Using Actions, Filters & Hooks
If you have built a WordPress theme before, you may find some of this guide familiar. However, beyond the stylesheet and functions setup, there are several special components and methods for working with the Layers API that are important to learn and comprehend, as the primary difference between a normal WordPress theme and a Layers child theme is that it must be designed to work with the functionality Layers (and by extension, the plugins created for Layers) provide.
Ready to start building your theme? Continue on with the next chapter linked below or Learn How to Setup a Local Development Environment first