Support » Plugins and Hacks » Hacks » Plugin Javascript Trying to Reference Plugins Directory

  • Resolved Adam Capriola


    I recently created my first official plugin (yay!) and realized I had a URL reference in my plugin’s JS file that might not work for certain sites:

    <img src="/wp-content/plugins/my-plugin/images/ellipsis.gif">

    I have kind of an AJAX thing going on in the Javascript, and that URL is for a loader image. I call the JS via wp_enqueue_script. I understand that the URL will work for most people, but if their WordPress installation isn’t at the base of their domain, then it will be a broken link.

    I know I could move the JS into one of my plugin’s PHP files and then use plugin_dir_url( __FILE__ ) or plugins_url() to grab the plugin URL and substitute that for part of the link, but I’d like to keep the Javascript as a separate file so I can utilize wp_enqueue_script.

    Is there a way around this?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugin Javascript Trying to Reference Plugins Directory’ is closed to new replies.