If you’re developing a WordPress plugin that depends on JavaScript or CSS you may advice WordPress to include these things for you. It’s as easy as using two functions – wp_enqueue_script and wp_enqueue_style – and your script or style will be embedded into each and every page generated by WordPress.
Most of the time this is a good thing because it’ll be easier for your users to implement the plugin on their sites. It gets really ugly if the theme loads certain scripts by default which are incompatible with the scripts needed by your plugin. And users concerned about performance – e.g. using Yahoo! YSlow or Google’s PageSpeed – may want to include only things that are really needed on a particular page.
This post presents a solution using custom fields that allows the user to tell the plugin when to include scripts and styles. Doing it this way helps the user to manage your plugin because of it’s added flexibility without hacking the code. Newbies trying to circumvent a certain incompatibility and power users tuning their sites to maximum performance both will love this feature of your plugin.