1

I'm creating WP Theme, I'm using slick slider and for nextArrow, prevArrow in main.js file, can't take image url path.

 prevArrow: '<img class="a-left control-c prev slick-prev" src="img/left-arrow.png">',
 nextArrow: '<img class="a-left control-c prev slick-prev" src="img/right-arrow.png">',

Also i have created one var in js

var templateUrl = '<?= get_bloginfo("template_url"); ?>';

and then, I have called this variable in this form:

prevArrow: '<img class="a-left control-c prev slick-prev" src="' + templateUrl + '/img/left-arrow.png">',

but did not work

2 Answers 2

2

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 use that variable for example to set the background (I realize you know how to do this, I only include these details in case it helps others):

Reset.style.background = " url('"+templateUrl+"/images/searchfield_clear.png') ";
Sign up to request clarification or add additional context in comments.

Comments

1

use something like this in your template:

var templateUrl = '<?= get_template_directory_uri(); ?>';

that will get you full url to theme directory, and then add your subdirectory "/img/.."

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.