Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDawn Foster
1,899 PointsFiles needed to Create a Child Theme
Hi Zac:
In your video you suggest we use this code in the style.css to setup using a child theme - and to import the parent stylesheet.
@import "../bootstrapWP/style.css";
However, Codex, says that: "@import should not be used to import the parent stylesheet into the child theme. The correct method is to use wp_enqueue_style() to enqueue the parent stylesheet, using this code in your child theme's "functions.php". "
If this is true... can you please update your Teacher's notes to indicate the change from what you are saying in the video?
So this is what I am using to setup my child theme.. can you verify if it is correct and complete? In the child-theme's folder there are these 4 files:
screenshot.png
index.php - (complete copy of the parent's index.php file)
style.css - as follows:
/*
Theme Name: bootstrap to WP child
Theme URI: http://mysite.com.au/
Author: Dawn Foster
Author URI: http://mysite.com.au/
Description: Child theme for the Template theme using Bootstrap.
Template: bootstrapWP
Version: 1.0
*/
/* =Theme customization starts here
-------------------------------------------------------------- */
function.php - as follows:
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style' );
function enqueue_parent_theme_style() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>
Is this all I need? I tried to cover all the items that have been suggested (in this video's questions, and elsewhere).. that might be required on different themes.
A couple extra questions:
Once I have created the child theme, and I look at it with a live demo option.. does it display exactly as it should look if it is activated? (When I do it on my child theme [that I created using the parent theme from the bootstrap course].. the home page shows blog widgets in the LHS column.)
And if I activate the child theme (just to see what it will look like), then try to go back and activate the parent theme.. do I loose any of the customisation from the original parent theme setup? Or is it totally seemless?
Thanks for your help. Dawn
1 Answer
Zac Gordon
Treehouse Guest TeacherHi,
Technically the approach you are taking is more correct, but when just starting sometimes we just use @import to simplify the overall process.
When you demo a theme it does not always look exactly the same, and unfortunately when you switch themes you do loose some of the configurations like widget placements or menus.