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 Build a Website with WordPress Customizing WordPress Themes How to Make Child Themes

Stefano Roversi
Stefano 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?

https://codex.wordpress.org/Child_Themes

Nice find. Unfortunately, I don't know too much about this I would also be interested in knowing more about this.

Kyzya Kooper
Kyzya Kooper
2,195 Points

yes, 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

The 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

  1. Creating stylesheet.css
  2. Creating functions.php
  3. Activating

It worked like a charm.

That'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.