在wordpress中调用js文件 [英] calling a js file in wordpress

查看:167
本文介绍了在wordpress中调用js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wordpress网站,我正在尝试向其中加载.js文件.由于某种原因,我无法使其正常工作.

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.

js文件位于 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?

推荐答案

这不是在wordpress中使用js文件的正确方法. 首先,您需要将js文件保存在主题文件夹上名为js的文件夹中.然后打开您的header.php文件,并使用它添加以下行:

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>

这会将您的js文件加载到wordpress网站. 编码愉快!

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

这篇关于在wordpress中调用js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆