How to load parent theme style.css?

My WordPress site uses a theme that is a child of a parent theme. As required, both themes have style.css files. However, as far as I can tell WordPress only provides the mechanism to load the child theme style.css file. How do the parent theme styles get loaded? Is it necessary to manually import the parent theme's style.css file into the child style.css file?

Topic parent-theme child-theme css themes Wordpress

Category Web


The process is simple, you can just create a functions.php file in your child theme directory and call the parent theme style:

Put the code!

function child_assets(){
    wp_enqueue_style( "parent-style" , get_parent_theme_file_uri( '/style.css' ) );
}
add_action( "wp_enqueue_scripts", "child_assets" );

In functions.php also load parent theme

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

function theme_enqueue_styles() 
{
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

At the top of your child themes style.css add:

@import url("../twentyeleven/style.css");

Obviously replace twentyeleven with your parent themes folder.

2016 - This practice has now been replaced by declaring the 'Template' in your theme stylesheet header:

Template:     twentyfifteen

https://codex.wordpress.org/Child_Themes


You can call the parent css as a separate file in your theme header.php Something like

<link href="<?php echo get_stylesheet_directory_uri(); ?>/css/css.css" rel="stylesheet">

Depending on various factors it may be better to copy and paste the parent css into your child css file, and thus no need to import it at all. Saves http requests etc.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.