• Hi. Trying to unravel dated information on this topic. As I understand it, as of 2017 you no longer need to enqueue the child theme stylesheet as WordPress automatically does it for you. Correct?

    What I want to do is add a version number to the child styles for helping with cache busting. I looked here: https://developer.ww.wp.xz.cn/themes/advanced-topics/child-themes/

    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'child-style', get_stylesheet_uri(),
            array( 'parenthandle' ), 
            wp_get_theme()->get('Version') // this only works if you have Version in the style header
        );
    }

    This added a versioned copy of my child stylesheet, but it was a duplicate! Would the proper thing to do is somehow dequeue the other child stylesheet?

    As far as the parent styles my current theme declares them like the below if that makes a difference.

    function child_enqueue_parent_theme_style() {
    	wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    add_action('wp_enqueue_scripts', 'child_enqueue_parent_theme_style');
Viewing 2 replies - 1 through 2 (of 2 total)
  • As I understand it, as of 2017 you no longer need to enqueue the child theme stylesheet as WordPress automatically does it for you.

    This is incorrect. WP has nothing to do with which stylesheets are loaded. It only provides the method of enqueuing with dependencies, but the theme and child theme must do the actual enqueue.

    I recently wrote the update to the page you are referring to, so I’d like to understand how I can make it more clear. Does it need to say explicitly that you have to substitute the parent handle for ‘parenthandle’?

    The code you quoted for your parent theme (yes, it does make a difference) looks like a mixture of parent and child. I can’t tell if that’s a direct quote or you changed it.

    Can you tell me which part of the explanation is confusing, so I can improve it?

    I forgot to say that if the parent theme really has that simple enqueue, with no version or dependency parameters, you should ask at the theme’s support forum for the author to add it. It will reduce support questions, because all of the users are having the same problem of not getting the cache busted, so not seeing the updates.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Enqueue child theme styles with versioning..’ is closed to new replies.