Week Four: Building Child Themes
Explain in your own words what a child theme is.
A child theme is a way of customizing an existing (parent) theme. A good metaphor for a child theme would be an apartment complex. All apartments have the same basic interior. This is a parent theme. Each tenant can then redecorate the apartment by painting, adding furniture, etc. but can’t change the structure in any way. You can’t change where the lights are or where the outlets are or knock down a wall. This is a child theme. Child themes are customized versions of the parent theme but in general most changes are cosmetic. However there are times when you can use a child theme to make major changes.
What is the difference between “overwriting” and “overridding”?
Overwriting is to make your changes directly to the existing (parent) theme. You open the code in the existing themes folder and alter it. This is risky and not advised because it then destroys any chance of implementing the original developer’s future updates to the existing theme. You would either not be able to update the theme or all your changes would be lost during the update.
Overridding is using a child theme to make the changes. You create the link to the parent theme in the child theme and use code to make the changes. WordPress recognizes that any code in the child theme takes precedence over code in the parent theme. The parent theme remains untouched so any updates will not completely destroy your changes.
How do you make a change in your child theme to a parent template file?
Any files in the child theme’s folder will take precedence over the parent theme’s files. So if you wanted to change the CSS for the child theme, you would first create a CSS file in the child theme’s folder. Then you would link the new CSS file to the parent’s CSS file at the top of the code. From there you can code the CSS to alter the appearance of the theme and changes will override the coding in the parent CSS.
How do you create a custom page template?
It depends on whether you are making a custom post page template or a custom static page template. For a custom post page template which would affect all posts, you would create a single.php file in your child theme folder. For a static page you would create a page.php file in your child theme folder. You can then copy the code you want from the parent theme’s .php file and position the coded items you want to keep in the way you want.
Explain what the header, footer and sidebar templates are for?
The header and footer templates are used as a way of creating moduler non-content sections on your site which will be placed on nearly every page on your site. The sidebar template is used in the same way but may not appear on every page. The header template will usually define the part of the website which would be used for a logo, Company name, etc. that usually appears at the top of the pages. Footers are used at the bottom of the page. The advantage of these templates is that if you need to make a change to the header or footer, you only need to make the changes on the one PHP file. I wish my initial Web 1 site had header, footer and other templates so I wouldn’t have had to make the changes on each of the 48 of my separate html page files.
What is the purpose of functions.php?
It is used to set up the features for your theme. It can define custom menus, style sheets and Java script. You can create a functions.php file in your child theme folder with code that will override the code in the parent theme’s functions.php file.
What is a widgetized area and how do you add functionality to it in the admin?
The widgetized area is one or more of the modular sections on your site where you can add a widget to show dated archives, categories, pages, recent comments, etc. You can add functionality by adding a widgetized area to your templates and then choosing what type of widget will show in that area using the dashboard.
How do you add a new featured image size?
You could change the featured image size in the functions.php file you created in your child theme folder. Once in the functions.php file, you can add a set_post_thumbnail_size () code which will specify the new featured image size. You can also adjust the size in your CSS file by finding the class for the featured image and in your child CSS file adding height, width, percentage, borders, etc.
If I had a custom sidebar for my blog pages, what could I name the template and how would I call it up? (Please write the filename and the code to call it in a template.)
Generally, the custom sidebar template in the child theme folder could be named sidebar2.php, sidebar3.php, etc. To then have this custom sidebar appear on your blog pages, you would open the single.php file in your child theme folder and add the code <?php include (‘sidebar2.php’); ?>.
What happens to your child theme when you update your parent theme?
Depends on how radically different the updated parent theme is to the original. Child theme changes will still take precidence even with the updated parent theme, but they may not appear as desired if the updated parent theme made certain changes.