Tagged: , ,

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #505093

    Having cache issues with child theme CSS, it always stays at ?ver=2
    Bug?

    #505132

    So, I found this in Enfold’s functions.php

    wp_register_style( 'avia-style' , $child_theme_url."/style.css", array(), '2', 'all' );

    That 2 is killing me :) Is there a way to make it dynamic, or remove and re-load via child theme functions?

    #505632

    Hey!

    Maybe replace it with $version_number? That would only change when you update Enfold though. I don’t know of a way to make it dynamic unless you parse the stylesheet contents and grab the version number from your comments.

    wp_register_style( 'avia-style' ,  $child_theme_url."/style.css", array(), 		$version_number, 'all' );
    

    I think it would be best to just finish editing and then clear your cache to see the changes.

    Best regards,
    Elliott

    • This reply was modified 8 years, 10 months ago by Elliott.
    #505764

    Is there a filter or something to remove the action that adds the child styles so they can be enqued on their own?

    How do others do this? I upload changes, and bump the style sheet version in the child style.css file each time. I then purge cache form Pagely dashboard, and hard reload in Chrome. Still nothing changes, have to wait hours it seems, or force view the style sheet in browser.

    Thank you.

    #506231

    Hey!

    It’s possible to remove a registered stylesheet then register a new one. Add something like this in the functions.php file:

    add_action( 'wp_enqueue_scripts', 'wp_enqueue_scripts_mod', 20 );
    
    function wp_enqueue_scripts_mod() {
        
        wp_dequeue_style( 'avia-child' );
        wp_deregister_style( 'avia-child' );
    
        wp_register_style( 'new-child-style', get_stylesheet_directory_uri() . '/new.css', false, '1.0.0' ); 
        wp_enqueue_style( 'new-child-style' );
    
    }
    

    Cheers!
    Ismael

    #748602

    It boggles my mind why the main Enfold functions.php file should add a version number to the child theme style.css file. This is what prevents it from auto-updating without a force-refresh or clearing your cache, which no one should have to do. That is the POINT of the version number.

    I have removed this hard-coded “2” from my child theme’s style.css file by adding the following code to my child theme’s functions.php file. Again, I did not alter the main Enfold functions.php file. I did this in my child theme’s functions.php:

    $child_theme_url = get_stylesheet_directory_uri();
    $theme_num = wp_get_theme()->get('Version');
    wp_register_style( 'avia-style' ,  $child_theme_url."/style.css", array(), $theme_num, 'all' );

    This allows WP to get the “Version” number you list in the top comments section of your child theme. By updating this number, you will now be able to have WP recognize your version number and auto-load the newest stylesheet version.

    I would certainly like to hear from the Enfold team why they would hard code that version number ‘2’ for any child theme. Is there a reason why you would do that? Does using the version number from the child theme stylesheet cause issues with Enfold? I can’t think of a reason why myself, but I would be happy to be enlightened.

    #748605

    Yeah there are several things I would do differently, but I cannot change them so I made a plugin to alter some stuff lol.
    Check it out if you like :)

    https://github.com/thatryan/enfold-tweaks

    #748608

    Thanks, thatryan!

    #777597

    ImageMagician, thank you so much. Those three lines of code saved my arse! Wish I’d had them MONTHS ago.

    #777608

    Glad it was helpful, Jan.

    #777700

    Hi,

    Let us if you need some help in the future :)

    Best regards,
    John Torvik

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Child Theme Styles Need Dynamic Version Number’ is closed to new replies.