Enqueue more than two CSS styles in a child theme functions.php

Child theme templates starts working before Parent theme, so if any similar template files (similar to parent theme) exists it tries to override the parent theme’s template – that’s the core thing about child theme.

The right way to enqueue new stylesheet in Child theme to make it THE Child Theme is the following:

<?php
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

With that in the functions.php and a style.css with proper Child Theme formatted comments you will get a complete new theme based on its parent. And you are done. 🙂

Now it’s your arena, override parent theme’s templates, override parent theme’s styles however you want. In one of my project, I added FontAwesome what was absent in parent theme, in this way:

In the above mentioned function I added a new line:

wp_enqueue_style( 'fontawesome-style', get_stylesheet_directory_uri() . '/css/font-awesome.min.css' );

Note that, I’m using get_stylesheet_directory_uri(), because now we are using new resources that is where the overriding stylesheet is. So all you additional stylesheet can be enqueued in this way:

Leave a Comment

tech