WordPress path url in js script file

To get the site url in the js file we can have different ways but worked for is listed below.
You could avoid hardcoding the full path by setting a JS variable in the header of your template, before wp_head() is called, holding the template URL. Like:

<script type="text/javascript">
var templateUrl = '<?= get_bloginfo("template_url"); ?>';
</script>

and call in js file

$("#nav-shadow li").append('<img class="shadow" src="'+templateUrl+'/images/shadow.jpg"/>');
Source : http://stackoverflow.com/questions/5221630/wordpress-path-url-in-js-script-file
Posted By AJJ

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.