admin管理员组

文章数量:1416305

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?

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?

Share Improve this question asked Aug 13, 2019 at 21:08 learningtechlearningtech 1971 silver badge14 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: themeswpenqueuestyle dep argument does nothing