0

I'm trying to make a child theme of the twentyseventeen theme. I started by making a style.css with the content:

/*
Theme Name: John Tries This
Template: twentyseventeen
*/

I then made this functions.php

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

    $parent_style = 'parent-style'; // This is 'twentyseventeen-style' for the Twenty Seventeen theme.

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

What I don't understand is the 3rd argument of wp_enqueue_style. You see that I have it commented out. My web page shows all my parent styles and templates regardless of whether or not I comment out the ,array($parent_style).

So what exactly does this 3rd argument do? The wordpress documentation says it is a list of dependencies. Why should I provide dependencies? What behaviour will it alter?

1

The 3rd argument of wp_enqueue_style means when enqueuing this stylesheet make sure it is after the list of dependencies.

In your case, prior to enqueueing the child-style WordPress make sure that parent-style is enqueued first.

Even though the enqueued statements are in the correct order:

wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css');

There will be an instance where child-style is enqueued first before the parent-style. So, to make sure that the order of the enqueued stylesheets are correct you need to supply the third argument, which is a list of dependencies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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