Child Themes Basics and Creating Child Themes in WordPress

A WordPress theme is a collection of template files which lets you change the user interface, design, look, and feel of the site. A WordPress theme can either just have some bare minimum design changes implemented or might even have some advanced logic showing the most recent post differently than the others or showing the posts from a particular category in a different section on the home page etc. WordPress themes can range from a simple set of files to a complete complex framework so that other themes can be built on top of that. In this article we are going to see how one can create child themes for other themes to leverage on the code provided by the parent theme.


Step 1 Understanding Child Theme Fundamentals

To create a child theme, first we have to create a folder in the wp-content/themes folder for our child theme. Then we create a style.css file in our child theme folder as shown below:

Once we have done this we should be able to see our theme in the wp-admin as seen below.

Now we can activate our child theme. Once we activate our child theme and see our blog we will see it all distorted as we have not provided any CSS in our style sheet. Here we are going to leverage and reuse the style from the parent theme and we will just include it in our child theme. Then just change the parts which we want to change. In this case we want to make the background grey. We should add the following lines to the style.css:

Now if we see our blog we will see it as seen below

The child theme has to contain a style.css file. Then the child theme could optionally override other template files like author.php, category.php etc. The WordPress framework first looks for a template file in the child theme directory and then if not found will pick it up from the parent directory. The child theme can also add its own functions.php to add its own functions and functionality in addition to that given from the parent theme.


Step 2 Understanding Advantages & Disadvantages of Using Child Themes

Using a child theme has many advantages some of which are as follows:

  • If we create a child theme we will not need to create a new theme from scratch which will have faster development time.
  • There are a lot of free and commercial theme frameworks available which give us a wide range of functionality will not need too much customization in our child themes.
  • If we use child themes as opposed to directly modifying the parent theme to suit our needs, we will easily be able to upgrade to a newer version of the parent theme without losing any of our customization.
  • A lot of times parent themes not only provide the design but also include widgets and plugins which can be directly used if we create a child theme of that parent theme.
  • If it's a popular parent theme you are using, either free or commercial, it's more likely to have fewer bugs and be more stable as it has been used and tested on multiple sites.

Some of the disadvantages of child themes are:

  • When we make child themes WordPress has to look into two places to find template files, this has some performance cost and hence using child themes might have some performance impacts on you site. Though in reality, these are very minimal.
  • A lot of the theme frameworks are very extensive and provide a lot of features which might not be useful to you. This makes frameworks complex and it would increase the time taken to learn and master the framework.

Step 3 Knowing Some Famous WordPress Theme Frameworks

There are a lot of free as well as commercial theme frameworks for WordPress than can be used as a parent theme. Some of them are generic and add a wide variety of functionality. There are also theme frameworks available for specific kinds of needs like creating a real estate site or creating a product catalog site etc.

Some of the free popular theme frameworks are:

  • Twenty Eleven - Though this is a complete theme, it is a very good starting point to create a child theme as it has all the functionalities to create a good web site. The style of this theme can be easily customized. This is a free theme and comes with the default WordPress installation. So it's a great framework to look at if you want to create a simple and cool web site.
  • Thematic - This is a very popular theme framework for WordPress. This is a free theme. This also has many child themes made on top of it which are also freely available. This theme framework has a lot of hooks which the child theme can use to customize. It also has multiple styles like 2-column and 3-column which can be used. It also has good documentation available which would make it easier to get started with this framework.
  • WhiteBoard - This is also a very good and useful framework. This comes with bare minimum functionality and good structure which can be customized for your needs. It's a very useful framework.

For a more comprehensive list of WordPress frameworks you can visit an interesting article The Wordpress Theme Frameworks Starter Guide


Step 4 Creating the Child Theme to TwentyEleven as an Example

Now we will change the design of the TwentyEleven parent theme in our child theme. Currently supposing we want a 2-column lay out with the sidebar at the right. In that case the layout we need is the same as that of the parent theme. So we will get that directly from the parent theme and we will not make any changes in the child theme.

For my child theme I do not want a header image. In TwentyEleven I can change or remove the header image from the theme options as shown below.

Following is the changes in the style.css of the child theme:

In the above code I have changed the background using the body tag, the menu items' design using the access, and the sidebar using the secondary tag. In similar ways you can change the design of any part of the parent to suit your needs. The theme will now look as seen below:

For more details on creating a child theme using TwentyEleven you can refer to the article Creating a Simple Child Theme Using Twenty Eleven.


Step 5 Creating a Child Theme for Thematic as an Example

Now we will create a child theme for Thematic. Once we have downloaded the Thematic theme and added it in our wp-content/themes folder we will add a new folder for our child theme called mythematicchildtheme. Inside the Thematic folder there is a folder thematicsamplechildtheme in which there are sample files to create a child theme from Thematic. We can use those files as starting point and paste them in our child theme folder.

Thematic has different layouts already defined which we can use in our child theme. For our child theme we will use a 3-coloumn layout. We will make some changes to the design of the site which are as follows:

The theme will look as follows:

Thematic also has a lot of hooks in the theme framework in which the child theme can hook into. Let's take the thematic_belowheader hook as an example and show the Hello Dolly lyrics which comes with the famous plugin Hello Dolly written by Matt Mullenweg which is in the WordPress installation by default. First let's activate the Hello Dolly plugin from the admin.

Then in the functions.php in the child theme add the following code:

Now we will display, at random, one line from the Hello dolly lyrics on the home page as seen below:

Thematic gives a lot of hooks which really make it easy for the child theme to add features using these hooks. You can get a list of all hooks provided by Thematic in the Thematic Guide's Theme Hooks page.


Conclusion

WordPress is a great platform to build blogs and sites. It also provides the infrastructure to create plugin frameworks or theme frameworks on top of it. The theme frameworks built on top of WordPress can help one develop a stable, good quality theme in quick time and will also let the uniqueness of your site remain intact. This helps in faster development time and lower costs. So have fun creating your WordPress child theme.

Tags:

Comments

Related Articles