0
votes

I'm trying to create a child theme and functions.php seems to be working but for some reason, the child theme isn't loading. I added the following in my functions.php and it does work, except it loads up the parent theme's style.css and not the child.

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

Here's the top of my style.css in the child:

/*
Theme Name: Chaplin Child
Theme URI: https://my-site.com/
description: Child Theme
Template: Chaplin
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: stack-child
*/
1
Your code is telling WordPress to load the parent theme's stylesheet only and that's it. That's why it doesn't load the stylesheet from your child theme. The documentation has examples on how to load both stylesheets, have you tried them out yet? - cabrerahector
Yes, I did. First version of the functions.php code didn't change anything. Second added the sheet but any style from the parent stylesheet overwrote the CSS in the child style sheet. - Adam Bell
Then the problem is how you're writing the CSS rules for your child theme. This is a good read: CSS Specificity. - cabrerahector

1 Answers

0
votes

Try this (in functions.php), this is from a working child theme of mine and also enqueues the child theme stylesheet:

add_action('wp_enqueue_scripts', 'register_my_scripts');

function register_my_scripts() {
    wp_enqueue_style( 'parent_style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css'  );
}