Finx
Finx

Reputation: 61

calling a js file in wordpress

I have a wordpress site and I'm trying to load a .js file to it. For some reason I can't get it to work.

The js file is at http://www.leadcomm.net/pricequotejs.js

and I put this in the footer:

 <script type="text/javascript">
 if (window.location.href == 'http://www.leadcomm.net/cost-estimate/') {    
     var js = document.createElement('script');
     js.setAttribute("type","text/javascript");
     js.setAttribute("src", "pricequotejs.js");
     document.getElementsByTagName("head")[0].appendChild(js);
 } 
 </script>

Any ideas on what I'm doing wrong?

Upvotes: 0

Views: 1154

Answers (3)

sobering
sobering

Reputation: 576

Is there any particular reason you can't use a standard HTML script tag?

<head>
    ...
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/pricequotejs.js"></script>
</head>

Upvotes: 0

Gaurav
Gaurav

Reputation: 628

this is not the proper manner to use a js file in wordpress. first you need to save your js file in a folder named js on you theme folder. then open your header.php file and use this add this line :

<script language="javascript" type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/your_file.js"></script>

this will load your js file to wordpress website. Happy coding!

Upvotes: 1

Finx
Finx

Reputation: 61

I left the document onload function. silly me...

Upvotes: 0

Related Questions