When deciding to customise a WordPress website the temptation is to edit the theme directly through changing or adding to files in the theme’s default folder. The main problem with this is that all changes will be lost if the developer updates the theme and you elect to allow the update. To not allow the update will leave you open to potential security risks with the old theme.
A better method is to use a ‘child theme’, which allows you to make any number of changes to a theme without any modifications to the original files.
Creating a Child Theme
To create a child theme, first create a new directory in your themes directory. The themes directory is located at wp-content/themes. The directory name should not include any spaces as part of the name and following common practice should preferably use the name of the parent theme folder with “-child” appended to it. For example, if you are making a child of the twentyeleven theme, your folder name would be twentyeleven-child.
A stylesheet file named style.css is then created and saved to the child theme directory. This is the only file required to make a child theme and it must start with the following lines:
/*
Theme Name: Twenty Eleven Child
Theme URI: http://mydomain.com/twentyeleven-child/
Description: Twenty Eleven Child Theme
Author: Fred Bloggs
Author URI: http://mydomain.com
Template: twentyeleven
Version: 1.0.0
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-fourteen-child
*/
@import url("../twentyeleven/style.css");
/* =Theme customization starts here
-------------------------------------------------------------- */
You can change each of these lines to suit your theme. The only required lines are the Theme Name, and the Template. The Template is the directory name of the parent theme. In this case, the parent theme is the TwentyEleven theme, so the Template is twentyeleven.
Because the child theme’s stylesheet is included after the parent theme’s then it’s styles will override those in the parent theme’s stylesheet (which is why they’re called cascading style sheets)
To activate the child theme, log in to your site’s dashboard, and go to Appearance > Themes. Here you will see your child theme listed and you click ‘Activate’ to use it.