将javascript加载到wordpress wp_enqueue_script()问题
我正在尝试让我的自定义 javascript (jQuery) 在 Wordpress 中正确加载。 我知道你必须使用 wp_enqueue_script() 才能正确执行此操作。然而我遇到的问题是结果不是我的脚本,但在我应该有 javascript 的地方我有 404 页面的代码! 我尝试了两种将脚本排队的方法:
wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),1);
就在 wp_head() 之上 和:函数 my_script_load() { wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),null); } add_action('init', 'my_script_load');
function.php 中的
两种方法具有相同的效果。当我检查 firebug 中的 HTML 时,我发现脚本被正确引用:
<script src="http://localhost/wordpress/wp-content/themes/doric2011/javascript/sitescript.js" type="text/javascript">
但是当我检查脚本本身时,我发现以下内容(摘录):` 找不到页面 |尼克·凯·尼尔森
等等...它是 404 页面的 HTML 输出,但占据了 javascript 应该的空间... 不用说,该脚本不起作用。
自从更新到 3.1 以来,我只遇到过这个问题,如果我尝试加载 highslide.js 和 highslide.config.js (专业编写的脚本),它也会做同样的事情。我希望加载的脚本已经在我的网站上运行,我想继续在我正在开发的新主题中使用它。
有人知道发生了什么吗?当然,我该怎么办呢?
这是本地安装 - 在解决此问题之前我不会冒险破坏我的网站。
I am trying to get my custom javascript (jQuery) to load correctly in Wordpress.
I know you have to use wp_enqueue_script() to do this correctly. However the problem I have is that the result is not my script, but in the place I should have javascript I have the code for a 404 page !
I've tried two ways of enqueueing the script :
wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),1);
just above wp_head()
and :function my_script_load() {
wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),null);
}
add_action('init', 'my_script_load');
in functions.php
both methods have the same effect. When I inspect the HTML in firebug I find the script is corredtly referenced :
<script src="http://localhost/wordpress/wp-content/themes/doric2011/javascript/sitescript.js" type="text/javascript">
however when I inspect the script itself I find the following (an extract) :`
Page not found | Nick Kai Nielsen
and so on... It is a HTML output for a 404 page, but occupying a space where javascript should be...
Needless to say the script does not work.
I have only had this problem since updating to 3.1 and it does the same thing if I try loading highslide.js and highslide.config.js (professionally written scripts). The script I wish to load is already working on my site and I want to go on using it in the new theme I am developing.
has anyone any idea of what is happening ? And, of course, what should I do about it ?
This is a local installation - I'm not risking breaking my site until this is sorted out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
假设您的 javascript 文件位于正确的位置(并且 URL 没有指向 JS 文件不的位置...),请尝试以下操作:
Assuming your javascript file is in the proper location (and the URL isn't pointing to a spot where the JS file isn't...) try this: