0

I made an template in HTML and now i am putting it in as an wordpress template. But in my .js file i got this:

    $('.tab_home').find('img').attr('src', '/images/home.png');

This is part of an click function and changes the image when i click on something. And it works fine in HTML but when i want to put this is in wordpress it is broken because the src url is wrong ofcourse. Now i did find this thread: WordPress path url in js script file and this would be part of my solution except that i can't put "+templateUrl+"in my .attr('src', '/images/home.png')Cause then i get an link like:

<img alt="" src=""+templateUrl+"/images/home.png">

Does some1 know what im doing wrong here, and how to fix it?

Thanks in forward.

1 Answer 1

2

You must do it as follows:

$('.tab_home').find('img').attr('src', templateUrl + '/images/home.png');

And don't forget to set templateUrl in the header of the template, as described in post you're referring to:

<script type="text/javascript">
var templateUrl = '<?= get_bloginfo("template_url"); ?>';
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Ow my ... Your totaly right, thanks alot. (I had the templateUrl right btw, just the syntax in my js file wrong.)

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.