Skip to content

Instantly share code, notes, and snippets.

@shrinkray
Last active December 28, 2019 15:47
Show Gist options
  • Save shrinkray/7936171e1e5a58565e5d3eeee6ea6a80 to your computer and use it in GitHub Desktop.
Save shrinkray/7936171e1e5a58565e5d3eeee6ea6a80 to your computer and use it in GitHub Desktop.
Webpack with hash filenames, Methods to enqueue
<?php
/**
* Enqueue a Hashed JS and CSS from Webpack
* Set theme stylesheet after WooCommerce.
*/
function enqueue_style_after_wc() {
// include the css file as hashed version
$cssFilePath = glob( get_stylesheet_directory() . '/dist/main.min.*' );
$cssFileURI = get_stylesheet_directory_uri() . '/dist/' . basename($cssFilePath[0]);
$ver = time();
wp_enqueue_style( 'tightlines-jewelry-theme', $cssFileURI, [], $ver );
}
add_action('wp_enqueue_scripts', 'enqueue_style_after_wc', 20 );
// include the javascript file as hashed version
$jsFilePath = glob( get_stylesheet_directory() . '/dist/app.min.*.js' );
$jsFileURI = get_stylesheet_directory_uri() . '/dist/' . basename($jsFilePath[0]);
$ver = time();
wp_enqueue_script( 'site_main_js', $jsFileURI , null, $ver, true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment