Discussion:
Adding Additional Attributes in Script Tag for 3rd party JS
Andrew Bartel
2013-08-26 22:11:11 UTC
Permalink
Hi All,

I asked this question on WPSE:
http://wordpress.stackexchange.com/questions/110929/adding-additional-attributes-in-script-tag-for-3rd-party-js
(and
added a bounty if anyone's interested at taking a crack).

I encountered this trying to add the dropbox dropin chooser app to a plugin
I'm writing. Their directions are to include <script type=
"text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id=
"dropboxjs" data-app-key="MY_APP_KEY"></script>' in the page.

I'm curious as to what the best practice is to pass additional attributes
to script tags so that the final output includes the attributes in the tag
itself. Including them with wp_localize_script() didn't seem to get them
registered by dropbox.

What's the best way to get those included when using the
wp_enqueue_script() function? Or is there an alternate function? Properly
hooked of course.

Thanks much,

Andrew
Otto
2013-08-26 22:36:53 UTC
Permalink
Post by Andrew Bartel
What's the best way to get those included when using the
wp_enqueue_script() function?
There is no way to do this short of overriding the WP_Scripts class
entirely to allow for extra attributes.

Even then, it's not possible to override WP_Scripts properly because
it's explicitly declared as a new class without a check or override in
a few admin places (load-scripts, customize, etc).

So basically, print it out yourself in the relevant *_head or
*_print_scripts action. No good way to enqueue it.

-Otto
Andrew Bartel
2013-08-26 23:38:56 UTC
Permalink
Thanks for the quick response and thorough explanation Otto.

-Andrew
Post by Otto
Post by Andrew Bartel
What's the best way to get those included when using the
wp_enqueue_script() function?
There is no way to do this short of overriding the WP_Scripts class
entirely to allow for extra attributes.
Even then, it's not possible to override WP_Scripts properly because
it's explicitly declared as a new class without a check or override in
a few admin places (load-scripts, customize, etc).
So basically, print it out yourself in the relevant *_head or
*_print_scripts action. No good way to enqueue it.
-Otto
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...