Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function wpwa_legendary_enqueue_hashed_js() {
$dirJS = new DirectoryIterator(get_stylesheet_directory() . '/static/js');
foreach ($dirJS as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'js') {
$fullName = basename($file);
$name = substr(basename($fullName), 0, strpos(basename($fullName), '.'));
switch($name) {
case 'app':
$deps = array('vendor');
break;
case 'vendor':
$deps = array('manifest');
break;
default:
$deps = null;
break;
}
wp_enqueue_script( $name, get_template_directory_uri() . '/static/js/' . $fullName, $deps, null, true );
}
}
}
add_action( 'wp_enqueue_scripts', 'wpwa_legendary_enqueue_hashed_js', 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment