I have an external script to integrate in a Wordpress theme. This script has different mixed resources in it like js, php files, etc. It's something like:
/mytheme/myscript/
...main.php
...folder/main.js
Now, main.js
post to main.php
and uses something like:
var comet = new vpb_start_comet('main.php');
comet.connect();
My problem's here. Main.php
is not found because I should change it with the relative wordpress path, being in a subfolder of my theme. So how could I get_bloginfo('template_url').'/myfolder/main.php
in my main.js
file?
If your
folder/main.js
is being included via thewp_enqueue_script()
function ( which it probably should be, as this is the proper method with WP to load scripts ), then you can easily add the theme directory uri as a variable using the `localize_script()' function like so:You would put this code after the wp_enqueue for the
main.js
script. This will make the theme directory available as a javascript variable namedthemeDirURI
, and the value will be something like: `http://www.example.com/wp-content/themes/theme-name/'Hope this helps!