1

When creating child them and setting up the initial function.php content:

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {

$parent_style = 'parent-style'; // <=====HERE

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

In this exemple should I rename 'parent-style' as the name of the parent style? Or leave it as 'parent-style'?

1
  • 2
    It’s not terribly important, but using a unique name, such as the theme name, reduces the chance of conflicts, although it’s unlikely a plugin will use the name ‘parent-style’. Apr 23, 2020 at 16:38

1 Answer 1

1

You can leave it as is (see Jacob Pettie's comment) or you can change it, but the key here is to add the path to locate the parent theme’s CSS.

<?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' );
 
}

In your example you’re cutting it off after the ( ‘parent-style’ ), but you should continue and include the path to the parent theme’s style.css.

get_template_directory_uri() is for the parent theme.

The full step by step breakdown can be found here: https://developer.wordpress.org/themes/advanced-topics/child-themes/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.