Skip to content

Instantly share code, notes, and snippets.

@billrobbins
Created November 19, 2018 13:04
Show Gist options
  • Select an option

  • Save billrobbins/745770cd462d26f62e64c8c0e237626d to your computer and use it in GitHub Desktop.

Select an option

Save billrobbins/745770cd462d26f62e64c8c0e237626d to your computer and use it in GitHub Desktop.
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