Tagged: cache, child theme, CSS
-
AuthorPosts
-
September 17, 2015 at 7:36 pm #505093
Having cache issues with child theme CSS, it always stays at ?ver=2
Bug?September 17, 2015 at 8:55 pm #505132So, 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?
September 18, 2015 at 4:14 pm #505632Hey!
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 9 years, 3 months ago by Elliott.
September 18, 2015 at 8:32 pm #505764Is 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.
September 21, 2015 at 7:11 am #506231Hey!
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!
IsmaelFebruary 17, 2017 at 7:34 pm #748602It 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.
February 17, 2017 at 7:37 pm #748605Yeah 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 :)February 17, 2017 at 7:39 pm #748608Thanks, thatryan!
April 14, 2017 at 12:56 am #777597ImageMagician, thank you so much. Those three lines of code saved my arse! Wish I’d had them MONTHS ago.
April 14, 2017 at 4:22 am #777608Glad it was helpful, Jan.
April 14, 2017 at 7:59 am #777700Hi,
Let us if you need some help in the future :)
Best regards,
John Torvik -
AuthorPosts
- The topic ‘Child Theme Styles Need Dynamic Version Number’ is closed to new replies.