force use of updated style sheet

3 Replies ·

  1. I want force browsers to reload cached style sheet after making changes to it.

    add_action( 'wp_enqueue_scripts', 'railtrail_enqueue_styles' );
    function railtrail_enqueue_styles() {
        $parent_style = 'parent-style'; 
        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') );
    }
    

    does not seem to work.

  2. Justin Tadlock

    You have to change the Version: xxx in your child theme’s style.css file for it to bust the cache with that method.

  3. markmcl

    yep, had done that, and cleared cache etc.
    also tried timestamp method.
    Oh well

  4. Justin Tadlock

    I should note that browsers do not have honor cache-busting techniques like that, but I’ve never seen them not do it. And, as far as I know, none of the major browsers have stopped.

    Check your site’s page source code on the front end and make sure the style.css file has something like ?ver=1.1.1 (whatever your version is) appended to the end of the URL. It’s possible that a plugin is removing the version number.

    If it’s not the problem, it’s a cache issue somewhere along the way. Whether that’s on the server level or on the browser level.