WordPress developers, please use wp_enqueue_script()

WordPress provides a number of useful JavaScript libraries for its plugin developers. They make it easy for plugin developers¬†to leverage these scripts in their plugins using the wp_enqueue_script() function ( not to mention various styling with wp_enqueue_style()¬†). In fact, if you are a plugin developer and unfamiliar with this function, I highly recommend you read through the documentation thoroughly and see what sort of scripts are already included in WordPress. It’s an essential function to know if you’re serious about developing plugins for WordPress. In fact, I make it a habit to look through the list with every major WordPress release to see if I can get rid of any custom JS libraries that I include in my plugins.

By utilizing WordPress’s included scripts, you are doing a service to people who use your plugin by:

  • Lessening the JS namespace pollution – the more you use the included scripts over other, 3rd party JS libraries, the less likely there will be any JS namespace conflicts.
  • As WordPress upgrades their scripts, so does your plugin by virtue of WordPress.
  • Your plugin takes up less space on the server by using already present scripts included with WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *