[resolved] Script handle naming convention (2 posts)

  1. RavanH
    Posted 4 years ago #


    As a plugin maintainer/dev I have come across some cases where several plugins include the same script or javascript library extension but register it with a different handle name with wp_register_script() or wp_enqueue_script()

    This will result in the same script (not the same file) being loaded twice when these plugins are used in combo. Sometimes it might even cause a js conflict.

    In one of my plugins I am using wp_deregister_script() to de-register possible instances of the same script just before registering the version included in my plugin package. I do this for several of the handle names that I have seen the same script being registered with in other plugins. Although this prevents most cases of the same script being loaded twice (or more) there are several disadvantages:
    1. This only works if I make sure I hook into enqueue_scripts with this wp_deregister_script stuff after all other plugins have done their thing;
    2. This might cause problems if by doing so, I accidentally de-register a script that (although registered under a similar name) has another function or is of another version;
    3. This will cause problems when the de-registered script handle is used as a dependency for another script. In this case, although the same script is re-registered, it is done so under different name and WP will drop the enqueueing of the new script that is dependant on the first one.

    Other cases might be possible, I imagine.

    So my question is: is there any naming convention for script handles when registering them in WP?

    Just picking three examples from the list on

    Official script file name » Script file in WP » Handle name
    jquery-1.6.2.js » jquery.js » jquery
    jquery-ui-1.8.min.js » ui.core.js » jquery-ui-core
    jquery.form.js » jquery.form.js » jquery-form
    jquery.schedule.js » jquery.schedule.js » schedule
    tiny_mce.js » tiny_mce.js » tiny_mce

    ... does not give me a clear picture at all...

  2. RavanH
    Posted 3 years ago #

    OK, responding to my own post here, just to let you now I got a response from Matt Varone on the thread http://wordpress.org/support/topic/plugin-easy-fancybox-its-not-compatible-with-dynamic-to-top

    He writes:

    Hi Again,

    Little update:

    After asking core developer Andew Nacin he suggested going with '-'. I have updated the Codex example accordingly, hopefully it will help prevent future issues like this.

    Kind Regards!

    Thanks Matt! Excellent :)

Topic Closed

This topic has been closed to new replies.

About this Topic