jQuery和Wordpress [英] jquery and wordpress
问题描述
我很难让我的jquery函数在wordpress中运行.
i am having difficulty making my jquery functions operate within wordpress.
任何人都可以帮忙,为什么这些功能应该可以正常运行,但不能在wordpress中使用?
can anyone help out with why these should work normally but not in wordpress???
推荐答案
似乎您必须使用wp_enque_script
加载脚本.您可以在结合使用jQuery和WordPress ,该脚本提供了脚本加载和使用示例代码.
It seems like you have to load the script using wp_enque_script
. You can find the documentation for this function and for loading scripts in WordPress in general at the codex page for wp_enque_script
. Furthermore, I found an article on Using jQuery with WordPress that provides sample code for the loading of the script and then the use of it.
如果您查看Codex文档,它会显示:
If you look at the Codex documentation, it says:
Wordpress附带的jQuery库在>没有冲突"模式.
因此,要照常使用$()
函数,您必须这样做
So to be able to use the $()
function as usual, you have to do
jQuery(document).ready(function($) {
// $() will work as an alias for jQuery() inside of this function
});
有关外观的示例,请查看上面链接的Themocracy文章的第2步.
For an example of what that looks like, look at step 2 of the Themocracy article linked above.
我很确定您会使用这些资源,希望它们能对您有所帮助.
I'm pretty sure you'll be fine with these resources, hope they help.
这篇关于jQuery和Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!