automating css version
-
After changing something in css, I will go to the page and do a force-reload (CTRL+F5) to make it reload the stylesheet so I can see if it worked.
Unfortunately, that is not an available option on my iPhone, so it’s difficult to see if the changes I made work there.
One solution is to change the version number on the stylesheet, but I can never remember to do that, after various minor tweaks.
So I found code online that will automatically change the version number, based on the save date/time, I think. ???♂?
I couldn’t find the code that calls the child theme stylesheet, so assumed it is called by wp_head, so placed this new code after that, knowing it would load the latest css.
It’s only just now that I am realizing it’s loading the css twice. And I just read that you shouldn’t put anything after wp_head except the closing head tag. Oops.
So what can I do with this magic code that works so well? This is the code I put in my header.php:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?v=' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
This is what is in my child theme’s functions.php regarding stylesheets:
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); }
I’m assuming there is a way to incorporate the first code with the second, but the second appears to only call the parent stylesheet, so I’m lost now as to how to apply this automated versioning to the child stylesheet.
Please help?
Thanks!
- The topic ‘automating css version’ is closed to new replies.