Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

RichardLight on "Wordpress variables in enqueued javascript"

$
0
0

Hi,

I want to include a SIMILE timeline in my Wordpress plugin, so need to include the relevant javascript library files. These require some initial settings to be specified in javascript, which include the folder where the timeline library files are installed.

Because I am enqueuing the SIMILE library, I also need to enqueue a little javascript file which sets these variables. This means that I can't just do it in PHP, e.g.:

Timeline_ajax_url="<?php plugins_url('js/timeline_2.3.0/timeline_ajax/simile-ajax-api.js', __FILE__);?>";
Timeline_urlPrefix="<?php plugins_url('js/timeline_2.3.0/timeline_js/', __FILE__);?>";
Timeline_parameters='bundle=true&timeline-use-local-resources';

because by the time this code runs, it's too late. I have tried pretending that a PHP file containing code like the above is actually a javascript file, and enqueuing it, but unsurprisingly this doesn't work.

So, how do I specify the Wordpress plugins URL variable from within javascript?

Thanks,

Richard


Viewing all articles
Browse latest Browse all 8245

Trending Articles