• Hoping this is actually the right place for this question and to receive some help! (Originally posted in Fixing WordPress, and it was suggested that I instead post in Theme: Argent, and there it was suggested that I instead post in this forum. 🙂

    I am using Argent as my theme (with a child theme), and I need to add a version number to the style.css sheet for cache busting purposes. I’ve Googled this and tried all the top hits for doing this such as adding a version number to wp_enqueue_style, adding this code to functions.php of my child theme, using filemtime as mentioned as method #2, and adding wp_get_theme()->get(‘Version’) as mentioned under #1, here.

    None of these methods have worked, mostly having no effect, and then occasionally crashing my staging site where I’ve been testing this. What can I use that will work?

    Here’s the relevant code from my child theme’s functions.php:

    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
     
    }

    …And here’s the relevant code from the Argent theme’s functions.php:

    /**
     * Enqueue scripts and styles.
     */
    function argent_scripts() {
    	wp_enqueue_style( 'argent-style', get_stylesheet_uri() );
    
    	wp_enqueue_style( 'argent-fonts', argent_fonts_url(), array(), null );
    
    	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
    
    	wp_enqueue_script( 'argent-js', get_template_directory_uri() . '/js/argent.js', array( 'jquery' ), '20150326', true );
    /* Change version from 20120206 */
    	wp_enqueue_script( 'argent-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
    
    	wp_enqueue_script( 'argent-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
    
    	if ( 'jetpack-portfolio' == get_post_type() && argent_get_gallery() ) {
    		wp_enqueue_style( 'argent-slick-css', get_template_directory_uri() . '/js/slick/slick.css' );
    		wp_enqueue_script( 'argent-slick-js', get_template_directory_uri() . '/js/slick/slick.js', array( 'jquery' ), '1.4.1', true );
    	}
    
    	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    		wp_enqueue_script( 'comment-reply' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'argent_scripts' );
    
    function argent_excerpt_length( $length ) {
    	return 20;
    }
    add_filter( 'excerpt_length', 'argent_excerpt_length', 999 );

    Any help is appreciated! Completely at a loss, though I’m sure it’s something very simple that I’m missing. Happy to go through re-trying any of the above methods, if helpful, too.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Your code doesn’t even put a version number on the one file it loads!
    The theme you are using is one that follows what I consider an anti-pattern, which means it does things in a way that is not what most people want.

    Because get_stylesheet_uri() checks the child folder first, it will load the child file if it exists or fallback to the parent file. That means the child then has to load the parent file! It also means that the wrong handle, version, and dependencies get associated with that file.
    Additionally, the first call to wp_enqueue_style for a handle will do something, but subsequent calls will not. So the child theme should load both child and parent files, with version numbers, or you need to go back to the theme support forum and get them to change how the parent style sheet is loaded, using the parent path and version instead of the child path and no version.

    Thread Starter hastibe

    (@hastibe)

    Ugh, well, I guess this explains why I found it so complicated to find instructions that worked to get my child theme’s CSS file to even load in the first place.

    So the child theme should load both child and parent files, with version numbers.

    The Argent theme hasn’t been updated in over a year, and when I posted this question there, the response I received is that this was “outside the scope of support for this theme” and to try posting here.

    So, if there’s any assistance you could provide with how to have my child theme load both child and parent files with version numbers, I would really appreciate that!

    In the child,

    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
      $theme = wp_get_theme();
      wp_enqueue_style( 'argent-style', get_template_directory_uri() . '/style.css', array(), $theme->parent->get( 'Version' ) );
      wp_enqueue_style( 'my-child-style', get_stylesheet_uri(), array( 'argent-style' ), $theme->get( 'Version') );
    }

    Doing this, the parent theme’s call to enqueue will have no effect, since child is loaded first.

    https://developer.ww.wp.xz.cn/reference/functions/wp_enqueue_style/
    https://developer.ww.wp.xz.cn/reference/classes/wp_theme/

    Thread Starter hastibe

    (@hastibe)

    Thanks for the reply, @joyously!

    I replaced the existing code (below) in my child theme’s functions.php file with the code you provided above, but it results in a “The site is experiencing technical difficulties.” error.

    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
     
    }

    I looked at the two reference pages you linked to and tried making various changes to try to get it to work, but couldn’t–are there placeholders in the code that you provided, which I need to provide the actual contents for?

    In case it is helpful, here is the header of my child theme’s style.css:

    /*
    Theme Name: Argent Child
    Theme URI: https://wordpress.com/themes/argent-child/
    Description: Argent is a clean and modern portfolio theme, geared towards creative professionals like designers, artists, and photographers. With its simple homepage template featuring portfolio projects, Argent aims to draw viewers right at what matters most: your wonderful work.
    Template: argent
    Version: 2.1.5
    Author: Automattic
    Author URI: https://wordpress.com/themes/
    License: GNU General Public License v2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Text Domain: argent-child
    Tags: custom-background, custom-colors, custom-header, custom-menu, featured-images, grid-layout, one-column, portfolio, rtl-language-support, threaded-comments, translation-ready
    */

    …And here’s the header of the Argent theme’s style.css:

    /*
    Theme Name: Argent
    Theme URI: https://wordpress.com/themes/argent/
    Description: Argent is a clean and modern portfolio theme, geared towards creative professionals like designers, artists, and photographers. With its simple homepage template featuring portfolio projects, Argent aims to draw viewers right at what matters most: your wonderful work.
    Version: 1.1.5
    Author: Automattic
    Author URI: https://wordpress.com/themes/
    License: GNU General Public License v2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Text Domain: argent
    Tags: custom-background, custom-colors, custom-header, custom-menu, featured-images, grid-layout, one-column, portfolio, rtl-language-support, threaded-comments, translation-ready
    
    This theme, like WordPress, is licensed under the GPL.
    Use it to make something cool, have fun, and share what you've learned with others.
    
    Argent is based on Underscores http://underscores.me/, (C) 2012-2016 Automattic, Inc.
    
    Normalizing styles have been helped along thanks to the fine work of
    Nicolas Gallagher and Jonathan Neal http://necolas.github.com/normalize.css/
    */

    I see it now, of course. I left out ().
    So where it says $theme->parent->get( 'Version' ) it should be
    $theme->parent()->get( 'Version' )

    Sorry.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @hastibe Moved to Fixing WordPress, this is not a Developing with WordPress topic.

    Please use that theme’s support forum instead as suggested.

    https://ww.wp.xz.cn/support/theme/argent/#new-post

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

The topic ‘Nothing Working to Version CSS Sheet’ is closed to new replies.