-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into hotfix/block-styles-template
- Loading branch information
Showing
5 changed files
with
55 additions
and
121 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Version Control for scripts and styles. | ||
* | ||
* @package wdsbt | ||
*/ | ||
|
||
namespace WebDevStudios\wdsbt; | ||
|
||
/** | ||
* Append file modification timestamp to CSS/JS assets for cache busting. | ||
* | ||
* @param string $src The original source URL of the enqueued asset. | ||
* @return string The modified source URL with version parameter. | ||
* | ||
* @author WebDevStudios | ||
*/ | ||
function style_script_version( $src ) { | ||
|
||
$style_file = get_stylesheet_directory() . '/style.css'; | ||
|
||
if ( file_exists( $style_file ) ) { | ||
$version = filemtime( $style_file ); | ||
|
||
if ( strpos( $src, 'ver=' ) !== false ) { | ||
$src = add_query_arg( 'ver', $version, $src ); | ||
} | ||
} | ||
|
||
return esc_url( $src ); | ||
} | ||
|
||
/** | ||
* Hook the custom versioning function to CSS and JS asset loading. | ||
*/ | ||
function css_js_versioning() { | ||
add_filter( 'style_loader_src', __NAMESPACE__ . '\style_script_version', 9999 ); | ||
|
||
add_filter( 'script_loader_src', __NAMESPACE__ . '\style_script_version', 9999 ); | ||
} | ||
|
||
add_action( 'init', __NAMESPACE__ . '\css_js_versioning' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters