Skip to content

Instantly share code, notes, and snippets.

@galengidman
Last active April 26, 2017 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galengidman/ca1b79acc22cf01f920ca9ad63eb1caf to your computer and use it in GitHub Desktop.
Save galengidman/ca1b79acc22cf01f920ca9ad63eb1caf to your computer and use it in GitHub Desktop.
<?php
function gg_asset_url( $path = '' ) {
return esc_url( get_template_directory_uri() . '/assets/' . $path );
}
function gg_asset_path( $path = '' ) {
return get_template_directory() . '/assets/' . $path;
}
function gg_assets() {
wp_enqueue_style(
'gg-style', // name
gg_asset_url( 'css/style.css' ), // file URL
array(), // dependencies
filemtime( gg_asset_path( 'css/style.css' ) ) // `ver` paramater value
);
wp_enqueue_script(
'gg-script', // name
gg_asset_url( 'js/script.js' ), // file URL
array( 'jquery' ), // dependencies
filemtime( gg_asset_path( 'js/script.js' ) ), // `ver` paramater value
);
}
add_action( 'wp_enqueue_scripts', 'gg_assets' );
<link rel="stylesheet" href="my/css/file.css?ver=<?php echo filemtime(__DIR__ . '/my/css/file.css'); ?>">
<script src="my/js/file.js?ver=<?php echo filemtime(__DIR__ . '/my/js/file.js'); ?>"></script>
<link rel="stylesheet" href="my/css/file.css?ver=<?php echo time(); ?>">
<script src="my/js/file.js?ver=<?php echo time(); ?>"></script>
<link rel="stylesheet" href="my/css/file.css?ver=1">
<script src="my/js/file.js?ver=1"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment