I’m using WordPress and I would like to use the value of <?php bloginfo('url'); ?> in a jQuery script file as a variable. Is that possible? And how?
In my script.js file I a function that uses:
$("#board").load("http://www.mysite.com/ajax/",{slug:post_slug});
and the “http://www.mysite.com” part will change (I’m building a theme).
Many thanks for your time and help.
What you’re asking for is not easily achieved, instead set a JavaScript variable in your
<head>element:Then you can use the
site_urlvariable in any of your JS files:August 2020 update
You should check out WordPress’ wp_localize_script function instead, this allows you to specify additional data to be made available to a queued script.
Here’s a good example by mikeschinkel on Github.