“I found out there was no child theme included. Dang! Now I have to create one!”
This is how we all sound when we have to create a child theme. There is really no rocket science to the process of creating child themes, but as a front-end fanatic, I always look for the best practices.
Today when I had to create a child theme, I thought of creating a boilerplate first, by DRY (Don’t Repeat Yourself) philosophy. So, there you go, a WordPress child theme boilerplate was born, and the only parent (me) chose to call it _child.
How to Stuff?#
There are only two files in _child. Which are
- style.css which has a tag template for the parent name
- functions.php which enqueues the style.css of parent theme and then style.css of _child
Inside _child’s style.css, there is nothing but a comment for WP to read it as a theme. At line #7 there is a template tag, which you need to replace with the folder’s name of your parent theme.
This file is a bit interesting. There’s a function called
aa_enqueue_styles() which is responsible for enqueuing two style sheets.
- First of all, I enqueued the parent theme’s style.css file
- Then I enqueued the child theme’s style.css with parent-stylesheet dependency, to ensure that the child theme stylesheet loads after the parent’s one.
If you have any questions, let me know.
_Child WP Child Theme Boilerplate#
It lives at GitHub under a tree called GPL license. Start it, fork it. Pull requests are welcomed!
Download v1.0.0 — Star or Fork
P.S. _child is an open-source theme, which means anyone can send pull requests to enhance it and make it better. My friend Matt Cromwell recently contributed to _child in the form of a branch called cleanup, _child in this branch dequeues and deregisters parent theme’s sidebars, widgets, post_types, and scripts (JS & CSS). Thus the name is cleanup.
P.P.S. A few beginner developers requested this gif on how to clone the _child boilerplate.
Takeaway my professional opinion on open-source, developer relations, growing your business with family, and everything in between! Delivered to your inbox a couple of times every year. I'm even funny at times. I hate spam — pinky-promise!
👨💻👩💻 118,947 Developers Already Subscribed