An Alternative to @import in WordPress Child Themes

I happened to find this by accident as I was creating a child theme to be able to help someone at the forums.

Basically, instead of doing this on the style.css of the child theme:

 * Theme Name: My Child Theme
 * Template: parent-theme
@import url(../parent-theme/style.css);

/* My Child Theme CSS */

Add the following on the functions.php of the child theme:

// Faster than @import
add_action( 'wp_enqueue_scripts', 'my_child_theme_scripts' );
function my_child_theme_scripts() {
   wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );

This alternative makes sense and it does work!

Leave a Reply