Title: Adding simple Javascript to pages
Last modified: August 19, 2016

---

# Adding simple Javascript to pages

 *  [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/)
 * According to this:
    [http://codex.wordpress.org/Using_Javascript#Javascript_in_Template_Files](http://codex.wordpress.org/Using_Javascript#Javascript_in_Template_Files)
 * Adding Javascript seems to be quite a hassle. I investigated the Inline JavaScript
   Plugin, but I don’t want to disable my WYSIWYG editor.
 * I am trying to embed weather for various locations on different pages, and the
   weather.com embed fits my needs best. The problem is that it’s Javascript, and
   I don’t know how to turn this into PHP:
 *     ```
       <div id="wx_module_3966">
          <a href="http://www.weather.com/weather/local/USCA0660">Malibu Weather Forecast, CA</a>
       </div>
   
       <script type="text/javascript">
          var wx_locID = 'USCA0660';
          var wx_targetDiv = 'wx_module_3966';
          var wx_config='SZ=300x250*WX=VWC*LNK=WWLD*UNT=F*BGC=e5e5e5*MAP=CSC|null*DN=www.roadreview.net*TIER=0*PID=1135549517*MD5=1d1a5d81581d186caf25d5bea18bec5a';
          document.write('<scr'+'ipt src="'+document.location.protocol+'//wow.weather.com/weather/wow/module/'+wx_locID+'?config='+wx_config+'&proto='+document.location.protocol+'&target='+wx_targetDiv+'"></scr'+'ipt>');
       </script>
       ```
   
 * Any help is much appreciated!

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

 *  [PBP_Editor](https://wordpress.org/support/users/pbp_editor/)
 * (@pbp_editor)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1291940)
 * Send me the page where you are taking this code from. I tried it in WordPress
   and on my local machine and it did not work.
 *  Thread Starter [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1291944)
 * There is the full code, I’m taking it from weather.com’s last page it generates
   after you configure your weather embed.
 * I could not get the code provided to work in WordPress either.
 *     ```
       <div id="wx_module_3966">
          <a href="http://www.weather.com/weather/local/USCA0660">Malibu Weather Forecast, CA</a>
       </div>
   
       <script type="text/javascript">
   
          /* Locations can be edited manually by updating 'wx_locID' below.  Please also update */
          /* the location name and link in the above div (wx_module) to reflect any changes made. */
          var wx_locID = 'USCA0660';
   
          /* If you are editing locations manually and are adding multiple modules to one page, each */
          /* module must have a unique div id.  Please append a unique # to the div above, as well */
          /* as the one referenced just below.  If you use the builder to create individual modules  */
          /* you will not need to edit these parameters. */
          var wx_targetDiv = 'wx_module_3966';
   
          /* Please do not change the configuration value [wx_config] manually - your module */
          /* will no longer function if you do.  If at any time you wish to modify this */
          /* configuration please use the graphical configuration tool found at */
          /* https://registration.weather.com/ursa/wow/step2 */
          var wx_config='SZ=300x250*WX=VWC*LNK=WWLD*UNT=F*BGC=e5e5e5*MAP=CSC|null*DN=www.roadreview.net*TIER=0*PID=1135549517*MD5=1d1a5d81581d186caf25d5bea18bec5a';
   
          document.write('<scr'+'ipt src="'+document.location.protocol+'//wow.weather.com/weather/wow/module/'+wx_locID+'?config='+wx_config+'&proto='+document.location.protocol+'&target='+wx_targetDiv+'"></scr'+'ipt>');
       </script>
       ```
   
 *  [PBP_Editor](https://wordpress.org/support/users/pbp_editor/)
 * (@pbp_editor)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1291946)
 * Take the script code and save it as an external js. WordPress doesn’t like the
   document.write directly in the post. Make sure you are in HTML edit mode.
 * So try this
 * <div id=”wx_module_3966″>
    [Malibu Weather Forecast, CA](http://www.weather.com/weather/local/USCA0660)
   </div>
 * <script type=’text/javascript’ src=’[http://yoursite.com/js/weather.js’></script&gt](http://yoursite.com/js/weather.js’></script&gt);
 *  Thread Starter [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292006)
 * I will try this out when I am near my computer later and will report back.
 * Thank you for your help.
 *  Thread Starter [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292210)
 * Hmm…that still did not work and I’m not sure why.
 * I pasted this into the WordPress page HTML editor:
 * <div id=”wx_module_3966″>
    Malibu Weather Forecast, CA </div>
 * <script type=’text/javascript’ src=’[http://roadreview.net/wp-content/uploads/2009/12/MalibuJS.js’></script&gt](http://roadreview.net/wp-content/uploads/2009/12/MalibuJS.js’></script&gt);
 * Any ideas anyone as to why this did not work?
 *  Thread Starter [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292211)
 * I also tried the code with single quotes changed to double quotes and that didn’t
   have any effect.
 *  Thread Starter [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292215)
 * Anyone have any ideas? I appreciate your time!
 *  Thread Starter [Wimbledon](https://wordpress.org/support/users/wimbledon/)
 * (@wimbledon)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292218)
 * Anyone in the night crowd have any ideas? Thank you.
 *  [theredone](https://wordpress.org/support/users/theredone/)
 * (@theredone)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292273)
 * Did anyone ever get this to work? I’m trying to do the same thing.
 *  [andoneyoung](https://wordpress.org/support/users/andoneyoung/)
 * (@andoneyoung)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292300)
 * It works exactly like PBP_Editor explained it above, he just didn’t walk you 
   through every single detail. I will use your code from above to help explain.
 * You still need the link to weather.com in your html code
 * ‘<div id=”wx_module_3966″>
    [Malibu Weather Forecast, CA](http://www.weather.com/weather/local/USCA0660)
   </div>’ Note for above, I’m new to all of this, but the code is not showing correctly
   above. It shows the link, but in your html code you need the entire href from
   the original weather.com code.
 * Next create an external java script using Notepad. Here is a link I found if 
   you are unsure of how to do that. [Link](http://www.htmlgoodies.com/beyond/javascript/article.php/3470901/So-You-Want-An-External-JavaScript-Huh.htm)
 * In the java script file include everything in between ‘<script type=”text/javascript”
   >’ and ‘</script>’, but do not include the tags you will use them later.
 * Upload your java script file to your server, it should be in the root directory
   for the website. If you want to put it in a new separate folder that is fine,
   just take note of where you put it, how you spell it, and how you space it and
   capitalize it. One difference will prevent the code from working.
 * Now go back to your page and the html editor. This is where you insert your tags
   again. Insert the code
    ‘<script type=’text/javascript’ src=’[http://yoursite.com/js/weather.js’></script>&#8217](http://yoursite.com/js/weather.js’></script>&#8217);
 * Note that /js/ is the folder the file is in. When I uploaded my .js file I put
   it in a separate Weather folder so instead I used /Weather/weather.js. Again 
   this script is very picky. If you have capitals in your file name you need to
   place capitals in the code.
 * I hope this helps, good luck, and pay it forward.
    You can check out the results
   on my page. [Protuber.com](http://www.protuber.com/locations/fall-city-wa)

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

The topic ‘Adding simple Javascript to pages’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 4 participants
 * Last reply from: [andoneyoung](https://wordpress.org/support/users/andoneyoung/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/adding-simple-javascript-to-pages/#post-1292300)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
