admin管理员组文章数量:1391943
I have a created a for each loop to load all the script files from my build folder dynamically in the footer with for development and production mode. This way I don't need to manually replace the script files.
But I have a problem, I don't know how to change the order of the files to a specific order.
It should be: Runtime, Vendors, Main.
This is my PHP code:
// First check if "JS" folder exist to prevent errors.
if(is_dir(THEME_DIR_ASSETS . '/js')) {
// Enqueue all scripts.
function nm_enqueue_scripts() {
$directoryJS = new DirectoryIterator(THEME_DIR_ASSETS . '/js');
wp_deregister_script('jquery');
wp_enqueue_script('jquery', '.2.4.min.js', array(), null, false);
foreach ($directoryJS as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'js') {
$fullName = basename($file);
$name = substr(basename($fullName), 0, strpos(basename($fullName), '.'));
wp_enqueue_script($name, THEME_DIR_JS . '/' . $fullName, $name, null, true);
}
}
}
add_action('wp_enqueue_scripts', 'nm_enqueue_scripts');
}
How can I do this?
本文标签: phpHow to change order inside foreach using wpenqueuescript
版权声明:本文标题:php - How to change order inside foreach using wp_enqueue_script? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744731022a2622047.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论