Need Javascript in Header on Wordpress, can I put it in separate file and CALL it ?

Discussion in 'HTML & Website Design' started by Karen May Jones, Feb 4, 2009.

  1. #1
    I have a html page that has this in the head area
      <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=550');");
    }
    // End -->
    </script>
    Code (markup):
    It's a little part of a popup code for a spell checker window I have on my site.

    I'm moving all of my site into a wordpress PHP script this week.

    I would like to put the spell checker on a php page as well on one of my wordpress pages.

    I need help.

    Should I put the code into the wordpress header?

    OR

    Is it possible to put the code and any other HEAD codes I need into a separate file and call upon them?

    If I fill the wordpress header file with a lot of codes will it hurt the loading too much?

    Thanks for opinion and input. Please help :)
     
    Karen May Jones, Feb 4, 2009 IP
  2. ExtremeData

    ExtremeData Well-Known Member

    Messages:
    450
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    125
    #2
    You can put the code into a .js page and call it into header.php file from your wordpress template.
     
    ExtremeData, Feb 4, 2009 IP
  3. Karen May Jones

    Karen May Jones Prominent Member

    Messages:
    3,469
    Likes Received:
    290
    Best Answers:
    1
    Trophy Points:
    380
    #3
    Can you please tell me how to write it out? Or example?
     
    Karen May Jones, Feb 4, 2009 IP
  4. ExtremeData

    ExtremeData Well-Known Member

    Messages:
    450
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Open header.php from your template directory and add this code before </head> tag :
    <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/file.js"></script>
    Code (markup):
    Create the file file.js and add your javascript code into it.
    file.js must be on your theme directory

    PS: on file.js you don't need <SCRIPT LANGUAGE="JavaScript"> and </script>
    So put the code without these tags.
     
    ExtremeData, Feb 5, 2009 IP
    JoyGoRound likes this.
  5. Karen May Jones

    Karen May Jones Prominent Member

    Messages:
    3,469
    Likes Received:
    290
    Best Answers:
    1
    Trophy Points:
    380
    #5
    Thank you for providing the key elements ;) to what I needed for the page. ++

    It worked :) here

    [​IMG]
     
    Karen May Jones, Feb 5, 2009 IP
  6. ExtremeData

    ExtremeData Well-Known Member

    Messages:
    450
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    125
    #6
    Glad to help you.
    PS:For your script I think you can make a rule to not consider two consecutive spaces as words.Just a suggestion.
     
    ExtremeData, Feb 5, 2009 IP