[wp-hackers] Loading JS & CSS from inside a plugin
Dave Ross
dave at davidmichaelross.com
Wed Mar 23 03:48:35 UTC 2011
On Tue, Mar 22, 2011 at 4:09 PM, Otto <otto at ottodestruct.com> wrote:
> Yikes. That's annoying.
>
> Better way:
>
> 1. Make your JS file static. Like a file named code.js. Put it in the
> same dir as the plugin.
>
> 2. wp_enqueue_script('code', plugin_dir_url(__FILE__).'code.js', 'jquery');
>
> -Otto
I just looked into this in more detail, and I'm not convinced this will
work. It's probably the proper way to do it, but I don't feel it's the right
way.
WP Subdomains is the bane of my existence. It doesn't redefine WP_PLUGIN_URL
(how could it?) and it doesn't implement the plugins_url filter. I don't
think plugin_dir_url() will know what to do with it. To make matters worse,
the WP Subdomains plugin hasn't been updated since 12/30/2009, so chances
are nobody will be updating it to do so anytime soon. But, I know from
experience that if I break compatibility with it, if I generate a script tag
that references a Javascript file on the main domain and not whatever
subdomain the user is visiting, I will wake up to an inbox full of
complaints. Nasty ones.
As much as I'd like to write back to each & every one of those people and
say "screw it, the plugin sucks and I don't care", that's not my way and I
don't think it's the WordPress way.
So how do other plugin authors deal with it?
More information about the wp-hackers
mailing list