Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple .css files in child theme

First working with child themes in WP.

I created a new folder in themes folder with the name my-theme-name-child and placed style.css file which works.

Now, the original theme has a responsive stylesheet which is located in my-theme-name/css/layout.css how do I replicate this in my child theme?

I created the folder css in my child theme and created layout.css there like this:

@import url("../my-original-theme/css/layout.css");

@media only screen and (min-width: 769px)

#header {
    padding: 20.618em 0 !important;
}
like image 680
Damir Avatar asked Dec 12 '25 11:12

Damir


2 Answers

I'd load the stylesheets directly instead. Open up functions.php inside your child theme and add the following code:

function wpse_load_parent_stylesheets() {
    wp_enqueue_style( 'layout', get_template_directory_uri() . '/css/layout.css' );
}
add_action( 'wp_enqueue_scripts', 'wpse_load_parent_stylesheets' );

Repeat wp_enqueue_style for each stylesheet you want to load.

like image 54
Nathan Dawson Avatar answered Dec 15 '25 07:12

Nathan Dawson


After creating layout.css in the css folder of your child theme, you will have to write the below function in child theme's function.php, in order to load it:

function load_child_stylesheet() {
    wp_enqueue_style( 'layout', get_stylesheet_directory_uri() . '/css/layout.css' );
}
add_action( 'wp_enqueue_scripts', 'load_child_stylesheet' );

You can refer this article which talks of a similar issue

like image 20
Domain Avatar answered Dec 15 '25 05:12

Domain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!