Child theme .css files are not overriding their parent .css files

In the last month I have been creating my very first website. Before this I had no coding knowledge so everyhting I learnt was new to me.

My problem over the last week is that my child theme .css files (and php. file but that is a different matter) are not overriding their parent .css files. I have been trying to search for a solution all week but have had no success so far.

This is the code I put into the child functions.php file

(1)

<?php

function my_theme_enqueue_styles()

{

$parent_style = ‘adforest-style’; // This is ‘adforest-style’ for the AdForest theme.

wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/css/modern.css’ );

wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/modern.css’, array( $parent_style ), wp_get_theme() >get(‘1.0.0’) );

}

add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );

?>

(2)

<?php

function my_theme_enqueue_styles()

{

$parent_style = ‘adforest-style’; // This is ‘adforest-style’ for the AdForest theme.

wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/css/modern.css’ );

wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/modern.css’, array( $parent_style ), wp_get_theme() >get(‘1.0.0’) );

}

add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’, 1 );

?>

(3)

<?php

function my_theme_enqueue_styles()

{

$parent_style = ‘adforest-style’; // This is ‘adforest-style’ for the AdForest theme.

wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/css/modern.css’ );

wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/modern.css’, array( $parent_style ), wp_get_theme() >get(‘1.0.0’) );

}

add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’, PHP_INT_MAX );

?>

(4) (Used in the modern.css child file)

@import url(“../css/modern.css”);

Any help is greatly appreciated from me 🙂

Read more here:: Child theme .css files are not overriding their parent .css files

Leave a Reply

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