0

I have been asked to make a wordpress site out of an html template wich uses some javascript. I'm not really familiar with js, but it is already been written so it shouldn't really make a problem. But there is something I cannot figure out, wich I guess it has to be really simple.

Normally I call my js and css files from the wordpress header.php like (for example):

<script src="<?php bloginfo('template_url'); ?>/js/jquery.cycle.all.js"></script>

so I use <?php bloginfo('template_url'); ?> as templateurl..

But in this template I have gotten there is a js file that calls other js files, and I can't write <?php bloginfo('template_url'); ?> there ofcourse.

It looks like this:

    document.writeln('<script type="text/javascript" src="'+ path +'some_js_file.js"></script>');

And my browser doesn't load this because it don't know where to look. How can I tell my browser where this file is, so that my js is working again??

I have already tried filling in the whole url of the js file, and I have also tried to just call that files in de header.php

Thanks in advance

4
  • As a sidenote, you should generally be using wp_enqueue_script when inserting scripts in Wordpress, not add them to the PHP directly. Commented Jan 18, 2014 at 14:13
  • See where the path variable is set in your js file and modify it. Commented Jan 18, 2014 at 14:13
  • why you cant preinclude second js file in header.php? Commented Jan 18, 2014 at 14:13
  • Thanks for the suggestions everyone, but I found out the things I tried weren´t working because of jquery, when I removed jQuery it worked again.. Commented Jan 18, 2014 at 14:51

1 Answer 1

1

Try defining the template url as a variable in the javascript on your page. Subsequent javascript files that your page loads should be able to access the same variable.

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

Then later on you can just use that variable:

$('#something').html("<img src='"+template_url+"/rest/of/path.jpg'>");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestion, but I found out the things I tried weren´t working because of jquery, when I removed jQuery it worked again..

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.