{"id":547,"date":"2011-02-22T11:55:47","date_gmt":"2011-02-22T11:55:47","guid":{"rendered":"https://www.divydovy.com/?p=547"},"modified":"2020-01-23T10:30:13","modified_gmt":"2020-01-23T10:30:13","slug":"css-cache-buster-for-wordpress-themes","status":"publish","type":"post","link":"https://www.divydovy.com/2011/02/css-cache-buster-for-wordpress-themes/","title":{"rendered":"CSS Cache Buster for WordPress Themes"},"content":{"rendered":"<p>A little while ago, <a title=\"Seamless CSS Updates\" href=\"/2009/07/seamless-css-updates/\">I expressed my joy at being able to avoid CSS cacheing-related issues</a> on websites that could result in poor user experience, by using the <a title=\"CSS Cache Buster\" href=\"http://www.alistercameron.com/2008/09/12/wordpress-plugin-css-cache-buster/\">CSS Cache Buster</a> plugin.</p>\n<p>Unfortunately, this has stopped working for me 🙁 Not sure if it&#8217;s the version of WordPress, or because I use child theming now. Either way, the demand for this fix maintained, so I&#8217;ve developed my own function for achieving this (leaning heavily on snippets from around the web, as always).</p>\n<p><code><br />\n// Add date-modified query to stylesheet to prevent CSS caching when CSS has changed.<br />\nfunction wpi_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri){</code></p>\n<p><code>if (!defined('STYLESHEETPATH'))<br />\ndefine('STYLESHEETPATH', get_stylesheet_directory());</p>\n<p>$csslastmodified = filemtime(STYLESHEETPATH.'/style.css');</p>\n<p></code></p>\n<p><code> if (!$csslastmodified == '') {<br />\nreturn $stylesheet_dir_uri.'/style.css?' . $csslastmodified;<br />\n} else {<br />\nreturn $stylesheet_dir_uri.'/style.css';<br />\n}<br />\n}<br />\nadd_filter('stylesheet_uri','wpi_stylesheet_uri',10,2);<br />\n</code></p>\n<p>As always, very happy to to be corrected, or for this to be improved upon, but it works great for me 🙂</p>\n","protected":false},"excerpt":{"rendered":"<p>A little while ago, I expressed my joy at being able to avoid CSS cacheing-related issues on websites that could result in poor user experience, by using the CSS Cache Buster plugin. Unfortunately, this has stopped working for me 🙁 Not sure if it&#8217;s the version of WordPress, or because I use child theming now. Either way, the demand for this fix maintained, so I&#8217;ve developed my own function for achieving this (leaning heavily on snippets from around the web, as always). // Add date-modified query to stylesheet to prevent CSS caching when CSS has changed. function wpi_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri){ if [&hellip;]</p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","clkt_auto_upload":"0","_clkt_publish_and_upload":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wordproof_timestamp":false},"categories":[7],"tags":[230,31,165],"my_content_publications":[],"class_list":["post-547","type-post","status-publish","format-standard","hentry","category-web","tag-cache","tag-css","tag-functions"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"clkt_attachments":{"featured_image":null,"inline_attachments":[],"upload_candidates":[],"max_free_size":102400,"max_allowed_size":104857600},"_clkt_upload_mode":"new_only","clkt_content_hash":"a8f4af917f7530ee06bea613929bf0a66568d4a7dfe9947971ad9cb3159d904d","customFields":{"clkt_auto_upload":"0","activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"processed_attachments":{"total_attachments":0,"uploaded_to_arweave":0,"kept_original_urls":0,"upload_summary":{"total":0,"uploaded":0,"failed":0,"too_large":0,"reused":0}}},"paymentAddress":"8_-tV4d15kVVq9Gd-Al2MAIC3LqNtJ_KgFol71TzxPw"}