The first function should be there in your parent theme functions.php file.
Parent Theme Code
<?php
if ( ! function_exists( 'my_theme_enqueue_scripts' ) ) {
function my_theme_enqueue_scripts() {
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' );
}
}
?>
Child Theme Code
Now place the following code in your child theme. Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it.
if ( ! function_exists( 'my_theme_enqueue_scripts' ) ) {
function my_theme_enqueue_scripts() {
wp_enqueue_style( 'my_parent_style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'my_child_style',
get_stylesheet_directory_uri() . '/style.css',
array('my_parent_style')
);
add_action( 'wp_enqueue_scripts','my_theme_enqueue_scripts' );
}
}
Hope it’s clear.
2nd Doubt
It’s recommended to add the rtl.css
file to your child theme even if the parent theme has no rtl.css
file. rtl.css
is only loaded by WordPress if is_rtl() returns true.