Skip to content
Advertisement

Plugin Javascript with Source URL’s For Images Using Wrong Directory

This is tough and would really, really love some help.

I have a plugin that has a JavaScript file with an array of sources (URL’s) that points to a “texture” directory in the plugin for images, but keep getting 404 errors, because instead of searching images in /website/wp-content/plugins/die/textures it looks for website/textures, or website/post-name/textures and never the plugin.

These work just fine on the same server as a generic html website, but WordPress is not behaving as expected. Here is the code to my plugin:

JavaScript

My Die.js code looks like this:

JavaScript

…with many more source: ‘./textures/pngs

The Die plugin directory structure looks like this:

  • includes
  • textures
  • die.php

Any input or help would be sincerely appreciated.

Thank you.

Advertisement

Answer

After you enqueue your js you need to localize your your variables from php like this:

JavaScript

You can access this “path” in your js as this:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement