[英]WordPress wp_enqueue_ scripts not working
I have a problem enqueing a superfish script into my website. 将超级鱼脚本放入我的网站时遇到问题。 I've been hours around it and I have no idea what's causing the problem.
我已经花了几个小时了,但我不知道是什么引起了问题。 I'm using a theme based on underscroes (this is my second time using it) and I enqueue the script in the functions.php using the
我使用的是基于下划线的主题(这是我第二次使用该主题),并且使用
wp_enqueue_script( 'kornelije-stankovic-superfish', get_template_directory_uri() . '/js/superfish.js', array('jquery'), '20140711', true );
I load the website using Chrome, check the resources and the script doesn't load. 我使用Chrome加载了网站,检查了资源,但脚本未加载。 Of course the script is in the /js folder with that exact name superfish.js.
当然,该脚本位于/ js文件夹中,其确切名称为superfish.js。
The funny thing is, that I tried loading it on the other website in the exact same manner and it works just fine! 有趣的是,我尝试以完全相同的方式将其加载到其他网站上,并且效果很好!
Any idea what could be causing this issue? 任何想法可能导致此问题吗?
The wp_enqueue_script()
should be called inside a wp_enqueue_scripts
callback, just like this: 应该在
wp_enqueue_scripts
回调内部调用wp_enqueue_script()
,如下所示:
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
Code from the WordPress Codex . 来自WordPress Codex的代码。
I would suggest you put the function call wp_enqueue_script( 'kor...
inside the _s_scripts()
in the functions.php
file (the function would have _s
replaced with your theme name ). 我建议您将函数调用
wp_enqueue_script( 'kor...
放在functions.php
文件的_s_scripts()
内(函数将_s
替换为您的主题名称)。
It seems it has been a WP Super Cache "problem." 看来这一直是WP Super Cache的“问题”。
It was on so the page wasn't refreshing instantly. 它在打开,因此页面没有立即刷新。
Thanks for help. 感谢帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.