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 trialStefano Roversi
2,088 Points@import functions
I read on the wordpress codex that using @import functions for child themes it is not the best practice anymore. Is it true?
Kyzya Kooper
2,195 Pointsyes, this is correct. They are no longer used. Instead you must now create a functions.php file inside of your child theme folder.
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
1 Answer
Marijke Celis
6,147 PointsThe use of @import seems to be obsolete, indeed. Apparently it increases the amount of time it takes style sheets to load. For me the @import didn't even work at all. I followed the steps that I found in the Theme Handbook here:
https://developer.wordpress.org/themes/advanced-topics/child-themes/#how-to-create-a-child-theme
- Creating stylesheet.css
- Creating functions.php
- Activating
It worked like a charm.
Brian Young
5,708 PointsThat's what I did as well, just because I like using 'BEST PRACTICES'. Might be worth @TeamTreehouse updating that peice of video just to keep things fresh and eliminate any confusion for students 'NEW' to WordPress.
James Rennie
16,807 PointsJames Rennie
16,807 PointsNice find. Unfortunately, I don't know too much about this I would also be interested in knowing more about this.