1

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
*/
3
  • 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? Commented May 26, 2020 at 22:23
  • 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. Commented May 29, 2020 at 4:11
  • Then the problem is how you're writing the CSS rules for your child theme. This is a good read: CSS Specificity. Commented May 29, 2020 at 11:06

1 Answer 1

2

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'  );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.