1

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

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

}

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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

At least, could you not try this ?

if($('#showcase').length) {
  $.include('/wp-content/themes/yourthemename/js/jquery.aw-showcase.js');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.