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 trial

WordPress How to Make a Website with WordPress Customizing WordPress Themes How to Make Child Themes

Zachary grace
Zachary grace
6,682 Points

@import rule

So in the WordPress video "How to make a child theme", Zac says to use the @import rule to import the stylesheet. I have heard that using the @import rule is not a good idea at all. Is it necessary for WordPress? or can you just use the link rule alternatively?

2 Answers

Joe Purdy
Joe Purdy
23,237 Points

You heard right. Using @import is less efficient than a link rule. In a nutshell multiple link rules will download simultaneously, however multiple @imports download one by one. However it is a Wordpress quirk that creates the need for @import to be used when creating child themes. There's a number of workarounds you can use if you're concerned with the performance hit from using @import. If you want to learn more about these workarounds I'd recommend the following blog article on the subject: http://wptest.means.us.com/2012/04/wordpress-child-themes-4-ways-to-avoid-inefficient-css-import/

And if you want to learn more about the technical reasoning behind why @import is less efficient there's a great blog post by Steve Sounders at http://www.stevesouders.com/blog/2009/04/09/dont-use-import/

Cheers!

Zachary grace
Zachary grace
6,682 Points

Thank you Joe! I appreciate your feedback! And thank you for giving me some great reading material!

Jason Brady
Jason Brady
17,372 Points

Additionally, the wordpress codex (http://codex.wordpress.org/Child_Themes) describes exactly how to go about correctly adding the child's style.css.

"@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"."