[wp-hackers] Re: Plugin interference

gbellucci gabellucci at gmail.com
Thu Apr 10 16:43:35 GMT 2008

Here is a simple example that includes:
   1. registering your scripts and dependencies
   2. gets the requested URI and looks for the name of your registered
plugin file
   3. adds one of several actions that will add information before the
</head> tag

/* Register your scripts with WordPress via the wp script loader*/
     array('jquery', 'depends-on-script-handle', ...), 'your-script-

/* get the currently requested URL */

/* Looking for my plugin's php entry point */
if( stristr($uri, '<your_plugin>.php') != false ) {

   // add action here for injecting scripts or css
   add_action('wp_print_scripts', array('classname',
   // or
   add_action('wp_admin_head', array('classname', 'function_name'));
   // or
   // or
else {
     ; /* not my page - so nothing to do */

I'm sure everyone does this a little bit differently, however, the
most important aspect of this is to only inject java script on pages
that you create for your plugin's backend options or on backend pages
that your scripts interact with - not on backend pages that are used
as administration/option pages created for use by other plugins.

Other gotch's include NOT injecting jQuery.js before Prototype.js

Maybe others have suggestions

More information about the wp-hackers mailing list