Man, the WordPress Codex is deep. I've spent more hours than I'd like to admit plumbing its depths, and I still get the sense I haven't seen more than a tenth of what it has to offer.
Here's a function straight from the codex that'll be a big help to theme and plugin developers: the
What's it for?
wp_enqueue_script() to include the most recent version of the library WordPress has available wherever you need it. Calling the function thusly will print a link to the script right before the end of your document's
- <?php wp_enqueue_script('jquery'); ?>
But what if I prefer to include jQuery with my plugin anyway?
Nothing's stopping you. But consider the possibility that the people who use your plugin or theme are likely to at some point install some other WordPress add-on that also uses jQuery or Scriptaculous. The big benefit to using
Cool. What else can it do?
- <?php wp_enqueue_script('dropdowns', '/wp-content/plugins/fancydropdowns/js/dropdowns.js', array('jquery'), '1.0' ); ?>
would automatically pull in links to both your script and the jQuery library. All you're giving it is what you're calling your script, the path where it can be found, its dependencies, and your script's version number, in that order.
I don't pick apart a ton of WordPress plugins, but having looked at the internals of a crazy number of themes in the last year, I can tell you that a bunch of them could benefit from this handy function.