0

This is my code to enqueue scripts. The later one with title yourscript2 is working, but the first one with title upload is not working:

add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
    wp_enqueue_script(
        'upload', 
        get_template_directory_uri() . '/js/upload.js',
        array( 'jquery' )
    );

    wp_enqueue_script(
        'yourscript2',
        get_template_directory_uri() . '/js/text.js',
        array( 'jquery' )
    );
}
  • 1
    Have you looked at page source and verified that the script tag is not present? Is the filename and path correct? I also suggest using a handle more unique than upload. – Milo Nov 21 '15 at 18:02
  • When I test this, it works insofar as the appropriate markup is inserted into the page. – s_ha_dum Nov 21 '15 at 18:03
0

Your upload.js is not being added because there is already an script added by wordpress as default for the handler upload.

So I suggest you to change the handler. If not, you can de-register the upload handler registered by wordpress

wp_deregister_script( 'upload' );

and then register yours as usual. But I highly recommend you to not de-register defaults function(which will lead to lot of conflict in upload of wordpress), so instead just change your handler.

@s_ha_dum the upload is inserting for you because the upload handler is not in latest wordpress versions. List of scripts registered by wordpress as of v3.8. So Usman Ahmed Mani might be using an old version of wordpress which has that upload handler

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.