Tyler
Tyler

Reputation: 11

Wordpress child theme does not override parent theme css

I am trying to create a child theme for the Wordpress theme twentyseventeen.

I have created a directory called twentyseventeen-child and within that I have created a functions.php and style.css file.

I can't work out why any changes I make to the child style.css are not implemented.

This is my child style.css:

/*
Theme Name: Twenty Seventeen Child
Theme URL: http://tylerdevries.com
Description: Twenty Seventeen Child Theme
Author: Tyler DeVries
Author URL: http://tylerdevries.com
Template: twentyseventeen
Version: 1.0.0
Text Domain: twentyseventeen-child
*/

This is my child functions.php

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

To test my new child theme I included the following code in my child style.css

.site-content-contain {
background-color: #d5ffa0;
position: relative;
}

I've also tried other simple css customizations - all to no affect.

Any help on what I'm doing wrong is greatly appreciated.

Upvotes: 1

Views: 2146

Answers (2)

Tyler
Tyler

Reputation: 11

Thanks for all the advice.

Turns out that my original code was correct. Problem had to do with my browser cache. After I cleared the cache, my changes were visible.

Upvotes: 0

Sithu
Sithu

Reputation: 11

// Queue parent style followed by child/customized style
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', PHP_INT_MAX);

function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/styles/child-style.css', array( 'parent-style' ) );
}

Upvotes: 1

Related Questions