Check javascript file Proper way in functions.php

Several pointers.

  • The latest WordPress version uses jQuery v1.10.2 , always use the
    bundled version for admin areas , for the front end you can use the
    bundled version or a CDN.

If you use a CDN make sure to still use jquery as a $handle so it is not loaded multiple times from other plugins/themes that also enqueue jQuery.

  • Use no conflict wrappers for your scripts, there are several methods
    you can read here:
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers
    this is essential.
  • Use better naming for your code, using name and your_enqueue is
    bad, try and be consistent and unique.
  • There is no reason to check if a function exists unless you plan to support child themes. Try and use conditional wrappers to only load your script where it is needed.
  • Not sure if it was a typo, but you do not need to include script src= in your .js file, this is what enqueue is doing.

Leave a Comment