php - How to change order inside foreach using wp_enqueue_script?

I have a created a for each loop to load all the script files from my build folder dynamically in the footer with for de

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744731023a4590466.html

相关推荐

  • php - How to change order inside foreach using wp_enqueue_script?

    I have a created a for each loop to load all the script files from my build folder dynamically in the footer with for de

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信