I’ve had success in adding JavaScript functions to my site by doing the following:
1. Save the JavaScript functions to be used to an external file. I’ve usually used the theme folder for the site I’m developing. So, if your theme is contained in root/wordpress/wp-content/themes/mytheme, I’d put the JavaScript function external file in a root/wordpress/wp-content/themes/mytheme/scripts directory.
2. Go into your header.php file for the theme. Towards the top of the file, find the links to the stylesheets and other things like pingback. Underneath those entires, add the following line to link to your JavaScript file (this code is used to make it pick up your theme directory name properly) (I’m assuming the file is named “scriptfile.js”):
<script type=”text/javascript” src=”<?php bloginfo(‘template_url’); ?>/scripts/scriptfile.js”></script>
3. You should now be able to use the JavaScript function in your template files. For something like this, I’d suggest using the function in the layout for the post, or maybe the sidebar.
You should note that if you’re trying to use these JavaScripts within the body of a, the default WordPress behavior of running posts through a formatter like Texturize or whatever…you may want to find a plugin that turns this off on a post-by-post basis, at least to test the script before altering your templates.
Hope this helps!!