[wp-hackers] Loading JS & CSS from inside a plugin
louie at louiemccoy.com
Tue Mar 22 21:16:35 UTC 2011
And to answer your users who will inevitably demand the ability to keep that
js from running on some pages, as of WP 3.1 you can have them include this
Works like a champ :-)
On Tue, Mar 22, 2011 at 5: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');
> On Tue, Mar 22, 2011 at 4:01 PM, Dave Ross <dave at davidmichaelross.com>
> > I'm the author of the Dave's WordPress Live Search plugin, and getting
> > I've spent way too many hours dealing with all the different
> > & plugins my users are using, including (but probably not limited to):
> > * Normal WordPress in Docroot
> > * Normal WordPress in a subdirectory
> > * WP Subdomains plugin
> > * wp-content in a non-standard location
> > * WPMU
> > Way back in my plugin's v1.0 days, I included the relevant JS & CSS in
> > page's <head>. But that upset a lot of devs who didn't want the same code
> > included in every page. It's redundant, but at least I could be
> > it would work.
> > As of the current dev version, I'm hooking into parse_request and
> > the static resource if a query parameter exists.
> > Here's how I'm loading one of the scripts:
> > define('DWLS_JS_PARAM', 'dwls_js');
> > wp_enqueue_script('jquery_dimensions', get_bloginfo('url') . "?" .
> > DWLS_JS_PARAM . '=dimensions', 'jquery');
> > It's slower than linking to a static file (WordPress has to start
> > but it works universally -- or so I thought. Today, I got two bug reports
> > for issues loading resources on WPMU, one of which is using the dev
> > My question in the short term is "what am I doing wrong?". Is there a
> > way I can link to a resource and be guaranteed it'll work across the
> > For the long term I'd like to request the addition of a new API, similar
> > Drupal's "Butler" project, which figures out a context from the site
> > and current page request, and can generate correct links to pages &
> > Plugins like WP Subdomains can hook into this API and change the rules it
> > uses to build URLs. I haven't thought out the details yet, but WP could
> > really use it.
> > Any help would be appreciated. I'm spending too much time tracking down
> > little compatibility issues and it's keeping me from making further
> > improvements to this plugin or even tackling other WordPress projects.
> > Thanks,
> > Dave
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers