How to path files in javascript?

I’ve this code in a fille called: general.js

if($('#showcase').length) {
$.include('js/jquery.aw-showcase.js');

}

Read More

But as we all know, WordPress uses bloginfo('template_url') to path files.

In front-end not work because show incorrect path <script type="text-javascript" src="js/jquery.aw-showcase.js"></script>

How to solve it?

Related posts

Leave a Reply

2 comments

  1. Maybe not the best solution, but you could always declare a JS variable early in your main index file, like such:

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

    Now, in your general.js file, you can reference it as such:

    if ($('#showcase').length) {
        $.include(template_url + '/js/jquery.aw-showcase.js');
    }
    

    You should usually avoid using a global variable, but it might be the only solution in this case.

    EDIT: You might actually want to use wp_localize_script instead of declaring a global variable.