如何在WordPress主题中使用jQuery?
我尝试在2011年WordPress主题中使用jQuery,我在标题中添加了以下内容:如何在WordPress主题中使用jQuery?,jquery,wordpress,themes,Jquery,Wordpress,Themes,我尝试在2011年WordPress主题中使用jQuery,我在标题中添加了以下内容: wp_enqueue_script( 'jquery' ); 并使用以下方法进行测试: <script type="text/javascript"> $(document).ready(function(){ alert("test"); }); </script> $(文档).ready(函数(){ 警报(“测试”); }); 我还使用jQu
wp_enqueue_script( 'jquery' );
并使用以下方法进行测试:
<script type="text/javascript">
$(document).ready(function(){
alert("test");
});
</script>
$(文档).ready(函数(){
警报(“测试”);
});
我还使用jQuery而不是$,但这不起作用
请帮忙,谢谢我前几天刚刚在Wordpress上看到这个问题。我只需将脚本添加到标题中,并确保jQuery正在运行,就可以解决这个问题 与其直接在标题中编写脚本,不如链接到外部文件(示例):
将它托管在服务器上的某个位置,然后链接到它——如果它包含事件处理程序,那么它们应该可以毫无问题地绑定 将此代码放在theme function.php中:
function custom_script() { ?>
<script type="text/javascript">
jQuery(document).ready(function(){
alert("test");
});
</script><?php
}
add_action('wp_head', 'custom_script');
函数自定义_脚本(){?>
jQuery(文档).ready(函数(){
警报(“测试”);
});
将此代码放在主题的header.php文件的(部分)中
现在你可以打电话了
<script type="text/javascript"
src="<?php bloginfo("template_url"); ?>/js/yourScript.js">
</script>
<script type="text/javascript"
src="<?php bloginfo("template_url"); ?>/js/yourScript.js">
</script>