Support » How-To and Troubleshooting » how to add javascrpit to a webpage

how to add javascrpit to a webpage

  • I’ve been at this for about 2 hours and had no progress. I know barely anything about javascript but this seems fairly straight forward, probably a matter of putting the code in the correct place.

    I want to put the calculator from this page – http://javascript.about.com/library/blfat2.htm on my page which is here – http://completemuscleandfitness.com/index.php/body-fat-calculator/

    I would really appreciate it if someone could tell me where in my header.php i need to put the following – <script type="text/javascript" src="fatcalc.js"></script>

    I have placed it in a number of places and still havent managed to get this calc to work.

    The actual fatcalc.js is curently placed in – htdocs/wp-content/themes/theme-name/fatcalc.js

    Should it be placed somewhere else?

    Thanks in advance for your help….

Viewing 15 replies - 1 through 15 (of 16 total)
  • This is my Header.php – http://pastebin.com/71Vv3kVQ



    Forum Moderator

    Read through that over and over, can’t grasp it….

    I did research before posting for help on here….



    Forum Moderator

    Thanks but that has baffled me even more!

    I was just hoping to get some direct help rather than links to pages…

    Really struggling with this



    Forum Moderator

    WordPress is free software and this free, volunteer-staffed forum is the only support resource available via wordpress.org. Here, we help people learn and help themselves rather than do the work for them. That said, if you cannot manage this yourself, perhaps you need to consider hiring someone to carry out the work for you.

    I’ve managed to get actual help on this forum previously rather than links.

    I’m not asking anyone to do the work for me, i asked for ‘help’

    I appreciate you providing the links for me, but I’ve already read through the stuff and haven’t managed to get any further afterwards, hence the reason for asking for help here.

    I cant afford to hire someone, again, the reason I’m asking for help here…..



    Forum Moderator

    All the information you need is on the two Codex pages that we have already posted here.



    Place it near this:

    <script type="text/javascript">
            document.documentElement.className = 'js';

    …and I guess you’ll want something like this:

    <script type="text/javascript" src="/wp-content/themes/theme-name/fatcalc.js"></script>

    …although the suggestion above for ‘wp_enqueue_script’ is the correct way to do it and I’m sure it has advantages as far as avaoiding conflicts between different scripts as well.

    If it’s not working then it could be a script conflict, so seriously look at the enqueue method.


    I find wp_enqueue_script really confusing.

    Is it possible to get this calculator working by using the information from here – http://codex.wordpress.org/Using_Javascript

    I’m trying my best to understand this, just don’t want to be wasting my time.



    Check your functions.php file as you may find it already enqueues scripts from there anyway, just add the calculator to it.

    Worth a look.

    Thanks Phil, appreciate the help. Had no luck with your first suggestion.

    I’ll have a look at the functions.php now

    Doesnt look like functions.php enqueues scripts.

    Thanks anyway, think it might be time to give up on this one…



    Why not get it working on a normal HTML or PHP page, then transfer it over to your WP site.

    I seem to be getting somewhere with a PHP page.

    You have been a great help thanks!!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘how to add javascrpit to a webpage’ is closed to new replies.