• Resolved gary_davison

    (@gary_davison)


    Hi,

    I am having a few issues with my template file. I have a image viewer which requires javascript to function. The javascript files are in a folder within my theme called js. I have linked the required javascript files to my index.php page through using the following code:

    <script type=”text/javascript” src=”js/jquery-1.2.6.js”></script>
    <script type=”text/javascript” src=”js/startstop-slider.js”></script>

    I have tested this as a oridnary PHP page and it functions fine. However when I upload it to WP it doesn’t work. Do I need my js folder to be located elsewhere outside of the theme? or do I need a different piece of code to include it?

    Any help would be great.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • <script type=”text/javascript” src=”js/jquery-1.2.6.js”></script>
    <script type=”text/javascript” src=”js/startstop-slider.js”></script>

    the above should not work using a normal php page, unless that .php page is being loaded on your browser like so:

    http://www.yourdomain.com/wp-content/themes/yourtheme/yourpage.php

    is that how you tested it?

    to use that code inside a theme file, you either need to move the js/ directory into your blogroot, or specify the path from your wordpress’ main index.php .. so you would use:

    <script type="text/javascript" src="wp-content/themes/mythemes/js/jquery-1.2.6.js"></script>

    same for the next one, as well.

    Thread Starter gary_davison

    (@gary_davison)

    Thanks

    I specified the path as you stated and it works perfectly.

    Cheers

    Could somebody help a newbie? This is EXACTLY what I need to do–link the js file under my theme.

    If it helps, I’m using the Inanis Glass theme. Could somebody please tell me where I should put the example:

    <script type=”text/javascript” src=”wp-content/themes/mythemes/js/jquery-1.2.6.js”></script>

    (with file name changes made of course)

    Thanks for any help you can give me.

    I’ve created a small plugin called Add JQuery that includes jQuery … cleaner than hacking the template and hard-linking to a script file.

    Download the zip file here
    .

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Linking to javascript files’ is closed to new replies.