1

I want to add a new Dropbox Drop In Chooser button to my site.

To include the code in a simple page you use

<script type = "text/javascript"
   src = "https://www.dropbox.com/static/api/1/dropins.js" id = "dropboxjs"
   data-app-key = "xxxxxxxx">

Where xxxxxxx is the dropbox supplied key for the app using the option. I know how to add a script using wp_enqueue_script, but I don't know if it's possible to add the data-app-key, if not what the correct way to add the script call in?

2
  • I am not not using this in a Template, but rather in a plugin. For this reason I want to add the script either from the php function or from the already enqueued js script with in the plugin. Commented Nov 16, 2014 at 17:21
  • 1
    I ran into this as well and ended up asking the same question. Lots of good answers here. Commented Nov 17, 2014 at 0:22

2 Answers 2

1

<script>YOUR CUSTOM JS CODE</script> inline does the same exact thing as YOUR CUSTOM JS CODE placed in a js file.

I see no problem with the use of your app key in a js file. There is a few points to consider here though

  • If your script is dependent on the main jquery library, just remember to set the $deps when you enqueue your script, otherwise it will not work if it loads to early

  • Make use of conditional tags to load your script only on selected pages

This way I cannot see that your script should fail

1

I contacted Dropbox support and they came back with another method to set the key which simply involves using the following javascript call, before creating the button.

Dropbox.init({ appKey: '<YOUR APP KEY>' });

I have added this to the helper script which handles the upload and passed the key down (which is stored in a standard Wordpress option field using the wp_localize_script function).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.