JavaScript WordPress - Plugin - enqueue image files from WP plugin directory in a JS-file wordpress plugin enqueue script,wordpress plugin enqueue style,wordpress plugin

I'm new with creating plugins for WP and I'm still learning. I have two questions concerning the same issue:

1: First I included the js-file in my plugins php-file:

function theme_name_scripts() {
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js');
}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

It works but what I want to do is to locate it from my plugins url (wordpress/wp-content/plugins/example), not from my template directory. How do I do this?

2: In my js-file, I need to include some image files from the plugin base url (wordpress/wp-content/plugins/example/pix). This script worked when not used as a plugin:

window.onload=function()
{

/* Example */

bp='/pix/', // base url of my images

imgnum=4, // number of images
thumb1=document.getElementById('thumb1'), // id of changing image
combobox1=document.getElementById('selection1'); // id of combobox.

combobox1.onchange=function()
{
thumb1.src=bp+'imagefile'+this.value+'.png';
}

I understand that bp='/pix/', is wrong. But what is correct? I want to load the images from a folder in template_directory. How do I do this? I have read through these two threads but I cant seem to figure it out:

Wordpress: How can I pick plugins directory in my javascript file?

write php inside javascript alert

Answer:1

(edited several times for clarity) Note: I am not the one writing the HTML. Here is the format of the HTML (note: the links and text after the links are on the same line): <li> <strong&...

(edited several times for clarity) Note: I am not the one writing the HTML. Here is the format of the HTML (note: the links and text after the links are on the same line): <li> <strong&...

  1. hanging indent text definition
  2. hanging text indent css
  3. indent hanging text
  4. hanging indent in text box powerpoint
  5. hanging indent in text citation
  6. html hanging indent text
  7. hanging indent rich text editor

I am trying to set up a Grunt project with bower dependencies with two tasks: development and deploy. The project folder structure currently looks like this: . ├── bower_components │   ├── animate....

I am trying to set up a Grunt project with bower dependencies with two tasks: development and deploy. The project folder structure currently looks like this: . ├── bower_components │   ├── animate....

looking at this event (being bind on 2 divs overlapping each other, look at the jsfiddle) .on('contextmenu', function() { ... }); Why do both divs being triggered? How can I detect this and or stop ...

looking at this event (being bind on 2 divs overlapping each other, look at the jsfiddle) .on('contextmenu', function() { ... }); Why do both divs being triggered? How can I detect this and or stop ...

  1. jquery event contextmenu
  2. jquery contextmenu event not working
  3. jquery context menu event
  4. jquery bind event contextmenu
  5. jquery event type contextmenu
  6. jquery event listener context menu
  7. jquery add contextmenu event
  8. jquery contextmenu event example
  9. jquery fire contextmenu event
  10. jquery add event listener context menu

I want to use the onreadystatechange event from the (underlying) XMLHttpRequest of JQuery's (2.0.2) $.ajax(...) to fire synchronous ajax requests so I can show an accurate status indication to the end ...

I want to use the onreadystatechange event from the (underlying) XMLHttpRequest of JQuery's (2.0.2) $.ajax(...) to fire synchronous ajax requests so I can show an accurate status indication to the end ...

  1. onreadystatechange event in ajax
  2. onreadystatechange event in javascript
  3. onreadystatechange event in js