Forums

[resolved] Linking to javascript files (5 posts)

  1. Gary_Davison
    Member
    Posted 3 years ago #

    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

  2. whooami
    Member
    Posted 3 years ago #

    <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.

  3. Gary_Davison
    Member
    Posted 3 years ago #

    Thanks

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

    Cheers

  4. lunantic
    Member
    Posted 3 years ago #

    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.

  5. abound
    Member
    Posted 3 years ago #

    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
    .

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.