• omniafausta

    (@omniafausta)


    Hi,

    I am problably just making a stupid mistake, hope you people can help me.
    I want to add a version to my childtheme’s css-link, but it looks like a older timestamp is already added by the parent theme?

    this is how I enqueue the styles in my functions:

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        $theme = wp_get_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 ), $theme->get('Version')  );
    }

    So what I expect to see is ?v=1.0.1 or something like that.
    What I get is ?ver=20190507

    What I see in the functions.php of the parent theme (twentyseventeen) is:

    // Theme stylesheet.
    wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri(), array(), '20190507' );

    But why would this effect the link to child-theme style instead of that of the parent theme???
    And ho do I get rid of that and replace it with the current version?

    Please someone point me in the right direction…

    • This topic was modified 6 years ago by omniafausta. Reason: edited out tying mistakes, and tried to make a sentence a bit cleare

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    You could read this page, which I expanded recently. https://developer.ww.wp.xz.cn/themes/advanced-topics/child-themes/#3-enqueue-stylesheet

    Your code uses the wrong handle for the parent theme. It is ‘twentyseventeen-style’, not ‘parent-style’. So since the parent is using get_stylesheet_uri() the child sheet gets loaded twice (under two handles). The stylesheet with the ‘parent-style’ handle has no version number, so it gets assigned the WP version. And the one with the handle ‘child-style’ has a variable $parent_style for the dependency, so whatever handle is in that variable will be output before the ‘child-style’. The first one (loaded by the child, with handle ‘child-style’) should have a version number that is in the child style.css headers. The second one (loaded by the parent, with handle ‘twentyseventeen-style’) will have the date version number.

    If you had used the same handle, the second call (by the parent) would not do anything. But it’s a bad way to do things. I tried to get them to change it before release (on 2017, 2019, and 2020), but they went by what the Handbook page said. So this year I get the Handbook page changed.

    Thread Starter omniafausta

    (@omniafausta)

    thank you very much for your extensive reply. This helps a lot in understanding!
    I’ll try it now and come back to here to tell you if it worked!

    Thread Starter omniafausta

    (@omniafausta)

    yes! thanks so much for your help!

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

The topic ‘Problem with css-version of childthem’ is closed to new replies.