• Hi! i’m having problems adding a javascript file in my wordpress theme for my blog. I’m using three javascript files; two for “nifty cube”(rounded corners) and one for the navbar menu but nothing seems to happen.This is my html:

    `<?php wp_get_archives(‘type=monthly&format=link’); ?>
    <?php //comments_popup_script(); // off by default ?>
    <?php wp_head(); ?>

    <script type=”text/javascript” src=”niftycube.js”></script>
    <script type=”text/javascript” src=”niftysk.js”></script>
    </head>
    <body>
    <div id=”logo”>
    </div>
    <div id=”envoltura”>
    <div id=”menu”>
    <script type=”text/javascript” src=”menu_.js”>
    </script>`

    Please, help me. Any reply will be appreciated.
    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • You need to use absolute (http) or site root relative (leading slash) links.

    Also see: https://codex.www.ads-software.com/Using_Javascript

    Thread Starter mayansoldier

    (@mayansoldier)

    sorry! what does that mean?
    I’m a still little newbie in html

    Thread Starter mayansoldier

    (@mayansoldier)

    Thanks a lot, i figured out what did you mean. But it didn’t work.

    src=”niftycube.js” is a relative link, something that you cannot use with WordPress. Put the http address of your javascript file in here instead.

    Thread Starter mayansoldier

    (@mayansoldier)

    Can i put a directory in my hard drive instead of an http adress?
    Its cause I’m using a dummy wordpress installed on my pc to develop this theme.

    You can put the javascript file in your current theme’s folder and then use:

    src="<?php bloginfo('template_url'); ?>/niftycube.js"

    Thread Starter mayansoldier

    (@mayansoldier)

    Oh man! thanks a lot! I couldn’t get to work the rounded corners script but i could with the menu script and thats enough
    Thanks a lot!!!

    simoneoor

    (@simoneoor)

    Many thanks from me as well. Spent all morning trying to get my javascript to work in the template, and it is this last tip from “iridiax” that finally sorted it!

    To recap (in case there are other beginners like me out there):

    in header.php, created after the meta section:

    <script type=”text/javascript” src=”<?php bloginfo(‘template_url’); ?>/Scripts/myscriptfile.js”></script>

    In the template index.php (somewhere in body between divs, but not in a post in this case):

    <script type=”text/javascript”><!–//–>
    <![CDATA[//><!–
    myfunction(); //–><!]]>
    </script>

    t31os

    (@t31os)

    Ah hah … spotted…

    <?php bloginfo('template_url'); ?>

    Been looking for a template URL function (well not been looking but waiting to see something for handling it)… ??

    Not related i know, but helpful to me… ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Help with javascript’ is closed to new replies.