Skip to main content

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.
To create a child theme, first we have to create a folder in the wp-content/themesfolder 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.phpcategory.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.
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.
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
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.
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 
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.

Comments

Popular posts from this blog

உடல் எடையை குறைக்க வேண்டுமா ?

இன்றைய அவசர உலகின் மிக பெரிய பிரச்சனையாக இருப்பது உடல் எடை அதிகரிப்பது தான்.மனம் போன போக்கில் உணவு கட்டு பாடு இல்லாமல் கண்டதையும் உள்ளே தள்ளுவதும்,உக்காந்த இடத்திலேயே கணணி முன் நேரத்தை விரயமாக்குவதும் தான் இந்த பிரச்சனைக்கு மூல காரணமாகும். அது சரி இந்த பிரச்சனையை எப்படி இல்லாமல் செய்வது அல்லது உடல் எடையை எவ்வாறு குறைப்பது என்பதை பற்றி பாப்போம் , பல வருட ஆரய்சிக்குபின் மருத்துவர்கள்   உடல் எடைய குறைக்க மிகவும் சுலபமான உடற்பயிற்சியை கண்டுபிடித்துள்ளனர்.இது  100% பயனளிக்க கூடியது, எந்த இடத்திலும் எந்தநேரத்திலும் மிக சுலபமா செய்ய கூடிய உடற் பயிற்சியாகும்.இந்த உடற்பயிற்சிகள் படத்துடன் கீழே தரப்பட்டுள்ளது நீங்களும் முயற்சித்து பாருங்கள கண்டிப்பாக பலன் கிடைக்கும்... முதலில் நாற்காலியில் உட்கார்ந்து இட  பக்கம் பார்கவும் .. ..        அடுத்து  நாற்காலியில் உட்கார்ந்து வல  பக்கம் பார்கவும்  ....  நண்பர்கள் யாரவது மச்சி வாடா சின்ன பீஸ் ,இங்க பாரு சூப்பர் அய்டம்னு சொல்லி கால்ல விழுந்து கூப்பிட்டலோ மேற்கூறிய உடற் பயிற்சிகளை முயற்சித்து பார்கவும் கண்டிப்பாக பலன் கிடைக்கும் .

38 (new) web tools to keep you busy

For many of us, the internet represents our daily job, income resource or biggest hobby. Every day we check our emails, read our feeds, visit our websites, find and discuss new things and GOD knows what else. It requires a lot of tools to do all this stuff and sometimes, we forget to search for easier solutions losing valuable time or keeping down the production graph. It's very hard to keep track with everything that's new and popular and this is why we do monthly searches for the best web tools out there. Enjoy!  45+ Web Operating Systems "There are many more web operating systems hoping to bring all your usual desktop applications online in one place - here are more than 45 of our favorites."  15 Ways To Create Website Screenshots "15 Ways To Create Website Screenshots"  Open Source Windows "The promise of open source software is best quality, flexibility and reliability. The only way to have TRUE "Open Source Windows"is

40 Fresh & Beautiful Examples of Websites With Large Backgrounds

Using large sized pictures or illustrations as your website’s background adds a great visual appeal to your website’s design. Many web designers use large images as backgrounds as more and more users are now opting for high resolution monitors and high speed internet connections. Here’s a showcase of 40 Fresh and amazing websites that are using large background images. 1.  The Pixel Blog 2.  Copimaj Interactive 3.  Flourish Web Design 4.  Abduction Lamp 5.  Morphix Design Studio 6.  Final Phase 7.  Make Photoshop Faster 8.  WebSarga 9.  Suie Paparude 10.  Duirwaigh Studios 11.  BlackMoon Design 12.  Sepitra 13.  Le Blog de Gruny 14.  Piipe 15.  Mozi Design Studio 16.  Electric Current 17.  Lora Bay Golf 18.  Life Style Sports 19.  ligne triez 20.  Oliver Kavanagh 21.  World of Merix Studio 22.  Le Web Defi 23.  How host 24.  Productive Dreams 25.  Gary Birnie 26.  Glocal Ventures 27.  GDR UK 28.  Absolute Bica 29.  Le Nordik 30.  Leaf Tea Shop & Bar 31.  Paul Smith 32.  EwingCole