0

I am working on a project that uses the child-theme's functions file to enqueue a stylesheet and a single javascript file. These two resources are enqueued well. However, when I add a new compiled javascript file, it doesn't seem to enqueue past the original two scripts at all, as if it is completely ignoring my addition to the functions.php file. Any idea why this is?

    <?php
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles_and_scripts' );
    function theme_enqueue_styles_and_scripts() {
        wp_enqueue_style( 'fonts', get_stylesheet_directory_uri() . '/assets/fonts/icons/style.css');
        wp_enqueue_script( 'script', get_stylesheet_directory_uri() . '/assets/js/main.js');
       wp_enqueue_script( 'script', get_stylesheet_directory_uri() . '/assets/compiled.js');
    }
1

Your second wp_enqueue_script() contains the same handle (the same ID) as the first wp_enqueue_script().

The handle is the ID by which a registered script is known to WordPress internally. If you use this ID a second time, the second script won't be registered.

A working example could be this one:

<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles_and_scripts' );
function theme_enqueue_styles_and_scripts() {
    wp_enqueue_style( 'fonts', get_stylesheet_directory_uri() . '/assets/fonts/icons/style.css');
    wp_enqueue_script( 'script', get_stylesheet_directory_uri() . '/assets/js/main.js');
   wp_enqueue_script( 'compiled-script', get_stylesheet_directory_uri() . '/assets/compiled.js');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.