Version of CSS theme - by Santhatela - on WordPress WooCommerce support

This topic has 4 replies, 2 voices, and was last updated 6 years ago ago by Olga Barlow

  • Avatar: identidade
    Santhatela
    Participant
    October 27, 2018 at 06:48

    Hello

    We know that today the fight between the updated css and the browser cache is complicated.

    I’m trying to put the theme version instead of the wordpress version with the code below:

    $theme = wp_get_theme();
    $ver = $theme->get( ‘Version’ );
    $themecsspath = get_stylesheet_directory() . ‘/style.css’;
    $style_ver = filemtime( $themecsspath );
    wp_enqueue_style( ‘theme-style’, get_stylesheet_uri(),array(),$style_ver );

    But I have a problem. It ends up loading 2 files as the image shows.

    version

    How could we solve this problem?

    I think it would be interesting to incorporate this function into the theme for the style and options css, because as it is a theme for sale we are always making changes and adjustments 🙂

    Thanks

    Rudimar

    3 Answers
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 30, 2018 at 16:09

    Hello,

    We will display the theme version for the style CSS in the next theme update. If you want to apply it now add the following code in child theme functions.php:

    add_filter( 'style_loader_src', 'etheme_change_style_ver', 10, 2 );
    add_filter( 'script_loader_src', 'etheme_change_style_ver', 10, 2 );
    function etheme_change_style_ver( $src ) {
        if ( is_child_theme() ) {
            $parent = wp_get_theme( 'xstore' );
    
            $parent_ver = $parent->get( 'Version' );
            $theme = wp_get_theme();
            $ver = $theme->get( 'Version' );
    
            if ( etheme_get_option( 'et_optimize_css' ) ) {
                $uri = get_stylesheet_directory_uri() . '/xstore.css';
    
                $uri_parent = get_template_directory_uri() . '/xstore.css';
            } else {
                $uri = get_stylesheet_directory_uri() . '/style.css';
    
                $uri_parent = get_template_directory_uri() . '/style.css';
            }
    
            if ( strpos( $src, $uri ) !== false ) {
                if( strpos( $src, '?ver=' ) ) {
                    $src = remove_query_arg( 'ver', $src );
                    $src = add_query_arg( array( 'ver'=>$ver ), $src );
                }
            } elseif( strpos( $src, $uri_parent ) !== false ){
                if( strpos( $src, '?ver=' ) ) {
                    $src = remove_query_arg( 'ver', $src );
                    $src = add_query_arg( array( 'ver'=>$parent_ver ), $src );
                }
            }
    
            return $src;   
    
        } else {
            $theme = wp_get_theme();
            $ver = $theme->get( 'Version' );
        }
    
        if ( etheme_get_option( 'et_optimize_css' ) ) {
            $uri = get_template_directory_uri() . '/xstore.css';
        } else {
            $uri = get_template_directory_uri() . '/style.css';
        }
    
        if ( strpos( $src, $uri ) !== false ) {
            if( strpos( $src, '?ver=' ) ) {
                $src = remove_query_arg( 'ver', $src );
                $src = add_query_arg( array( 'ver'=>$ver ), $src );
            }
        }
    return $src;   
    }

    Regards

    Avatar: identidade
    Santhatela
    Participant
    October 31, 2018 at 08:10

    Thanks Olga

    I believe this is a great improvement.

    Many developers are looking for speeding site removing the versions of the files. But I studied for 2 years the behavior of customers and the ideal score to have consistent sales is something around 90 points in pagespeed. Above this there is no difference in sales and possibly compatibility issues.

    Upgrades in the store drops sales 30%, due to broken or incorrectly displayed layouts. Customer interprets as a problem site and abandons your purchase.

    So keep the updated versions for correct loading, to my understanding is very important.

    Thanks again

    Rudimar

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    November 1, 2018 at 12:28

    Hello,

    Yes, sure. we’ll implement this in next theme update.

    Regards

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.