I tried to make a child theme to change some colors. I used this https://codex.wordpress.org/Child_Themes tutorial, but I still can’t get this done. The problem is that I am not able to override some styles, because my stylesheet called “bootstrap.css” is not getting loaded.
My functions.php file looks like this

<?php
function my_theme_enqueue_styles() {
    $parent_style="maxstore_theme_stylesheets"; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/bootstrap.css' );
    wp_enqueue_style( 'child-style', get_template_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version'));
    wp_enqueue_style( 'child-style', get_template_directory_uri() . '/css/bootstrap.css', array( $parent_style ), wp_get_theme()->get('Version'));
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

These are the files that are getting loaded
enter image description here

EDIT 1:
I’m now using this code and it still isn’t working

<?php
function my_theme_enqueue_styles() {
    $parent_style="maxstore_theme_stylesheets"; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/bootstrap.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version'));
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/css/bootstrap.css', array( $parent_style ), wp_get_theme()->get('Version'));
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

EDIT 2:
My bootstrap stylesheet is getting loaded, but for some reason my website is still using another version of it. As you can see it uses 3 times the same styles and the one that is really used is version 3.3.4. and I want to use the one with the blue color which is version 1.0.2
enter image description here
Version 3.3.4 in the picture and I want to use the bootstrap version 1.0.2.
enter image description here
EDIT 3:
Code from functions.php that I am using at the moment

<?php
function my_theme_enqueue_styles() {

    $parent_styles = array('maxstore_theme_style', 'maxstore_theme_bootstrap'); 
// This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    wp_enqueue_style( $parent_styles[0], get_template_directory_uri() . 
'/style.css' );
    wp_enqueue_style( $parent_styles[1], get_template_directory_uri() . 
'/css/bootstrap.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . 
'/style.css', $parent_styles, wp_get_theme()->get('Version'));
    wp_enqueue_style( 'child-bootstrap', get_stylesheet_directory_uri() . 
'/css/bootstrap.css', $parent_styles, wp_get_theme()->get('Version'));
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

2 Answers
2

Parent vs Child Themes

get_template_directory_uri always refers to the parent theme you can verify this as you always should when things don’t load as expected by looking in the console in the browsers dev tools. These would show 404 errors for the CSS files, in the wrong folder.

Instead, use get_stylesheet_directory_uri, the stylesheet family of functions always refer to the current active theme

Duplicated Names

wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version'));
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/css/bootstrap.css', array( $parent_style ), wp_get_theme()->get('Version'));

You can’t call 2 stylesheets the same thing and expect it to work, which is what you’ve done with all 4 of your stylesheets

Also notice that you’ve loaded bootstrap.css from both themes

Leave a Reply

Your email address will not be published. Required fields are marked *