Title: How to add Java Script to comments page?
Last modified: August 18, 2016

---

# How to add Java Script to comments page?

 *  [tezzer](https://wordpress.org/support/users/tezzer/)
 * (@tezzer)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/)
 * Hi, I would like to add an invisible stats counter (java) to my comments pages.
   The 2 pages where my comment form is:
 * [http://friedbrains.com/?p=58](http://friedbrains.com/?p=58)
 * [http://friedbrains.com/?p=58#respond](http://friedbrains.com/?p=58#respond)
 * I have successfully added it to my index page and page template. I have tried
   adding it to the comments template, but it doesn’t show up in source??? Does 
   anyone know what I am doing wrong or what I need to do?
 * Regards Tezzer

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

 *  [spencerp](https://wordpress.org/support/users/spencerp/)
 * (@spencerp)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459834)
 * Some reads from here might help maybe:
    [http://codex.wordpress.org/Using_Javascript#Javascript_in_Template_Files](http://codex.wordpress.org/Using_Javascript#Javascript_in_Template_Files)
 * Not sure if ya read that already..but, worth a shot right? =)
 * spencerp
 *  Thread Starter [tezzer](https://wordpress.org/support/users/tezzer/)
 * (@tezzer)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459838)
 * Spencerp, the following is from that link you gave me:
 * “To use Javascript repeatedly within your site, you can either set the call for
   the Javascript, **or the script itself,** in the head of your header.php template
   file, between the meta tags and the style sheet link, no differently than you
   would if you were using Javascript in any HTML page. To “load” the Javascript
   file into your site, in the head, add something like this”
 * Does this mean that if I paste my java script in the head, without a call to 
   it, it will work?
 * Regards Tezzer
 *  [spencerp](https://wordpress.org/support/users/spencerp/)
 * (@spencerp)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459839)
 * Well, what I was doing before.. was, added the call to it like such (In the header.
   php):
 * `<script type="text/javascript" src="/scripts/updatepage.js"></script>`
 * Then, in my theme’s file(s).. added the CALL CODE FOR that specific javascript
   stuff also.. I’ll have to find an example once.. Since my hard drive crash Two
   weeks ago.. I lost alot of my stuff.. Let me try and find it once.. In the meantime,
   maybe someone else can help ya..
 * spencerp
 *  [spencerp](https://wordpress.org/support/users/spencerp/)
 * (@spencerp)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459840)
 * Ok, here’s what I had done before, of course.. this is an example ONLY.. so, 
   please keep this in mind lol..
 * I had made a main Javascript file, for various javasript stuff, just inside ONE
   file. Here’s from a theme’s header.php file of mine..
 * `<!-- JavaScripts -->`
    `<script language="javascript" type="text/javascript"
   src="<?php bloginfo('stylesheet_directory'); ?>/javascripts/scripts.js"></script
   >`
 * In that: /javascripts/scripts.js file, I had for the Quote Comment plugin:
 * `/* Quote comment`
    `----------------------*/` `function quote(comment, author){``
   theContent =` `document.getElementById(comment).innerHTML;` `theContent = theContent.
   replace(/ /g, "");` `theContent = theContent.replace(/<p>/g, "");` `theContent
   = theContent.replace(/</s*p>/g,` `"n");` `theContent = theContent.replace(/<br
   >/g, "")`
 *  `if (document.getElementById("comment").value ==` `"") {`
    `document.getElementById("
   comment").value` `+= "<strong>" + author + "</strong> said:` `nn<blockquote>"
   + theContent + "</blockquote>";` `} else {` `document.getElementById("comment").
   value` `+= "nn<strong>" + author + "</strong> said:` `nn<blockquote>" + theContent
   + "</blockquote>";` `}`
 * Then in the comments.php file, I had this to call for it:
 * `<?php if (comments_open()) { ?>` `<a href="#commentform" title="<?php _e('Quote
   this comment')` `?>" onclick="quote('comment-<?php comment_ID() ?>',` `'<?php
   echo($comment->comment_author); ?>')"><?php` `_e('Quote') ?></a> | <?php } ?>`
 * I hope this helps maybe.. =/
 * spencerp
 *  [NuclearMoose](https://wordpress.org/support/users/nuclearmoose/)
 * (@nuclearmoose)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459842)
 * What if the visitor has JS disabled in their browser? Won’t that affect your 
   counter?
 *  Thread Starter [tezzer](https://wordpress.org/support/users/tezzer/)
 * (@tezzer)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459851)
 * Thanks, Spencerp, but that seems a lot of work for what I want. I don’t really
   need my counter on every page (just on my comments pages). I was able to simply
   cut and paste it into my index and page templates and it works fine there, so
   all I am really asking for is a way to cut and paste it into my comments pages?
 * Regards Tezzer
 *  Thread Starter [tezzer](https://wordpress.org/support/users/tezzer/)
 * (@tezzer)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459860)
 * Thanks, Spencerp, I think I have solved my problem now. Or at least I think I
   have. I was able to paste the java directly into my comments template afterall.
   I am sorry for causing you work.
 * I will test it over the next day and see if it works properly.
 * Thanks Tezzer
 *  [spencerp](https://wordpress.org/support/users/spencerp/)
 * (@spencerp)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459863)
 * Hey, it’s ok Tezzer.. It was no trouble at all. ;)=) I hope it works like you
   want, and let us know how things work too ok? =)
 * spencerp

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

The topic ‘How to add Java Script to comments page?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [spencerp](https://wordpress.org/support/users/spencerp/)
 * Last activity: [19 years, 8 months ago](https://wordpress.org/support/topic/how-to-add-java-script-to-comments-page/#post-459863)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
