wordpress如何调用js
wordpress调用js的方法:
一般在主题的header.php文件中直接引用,有些主题还会通过WP自带的函数wp_enqueue_scripts加载主题的functions.php文件中的JS文件。
1.将文件直接引入主题header.php文件,例如
& lt脚本类型= & # 039;text/JavaScript & # 039;src = & # 039http://www . jquery . com/js/jquery/1 . 10 . 2/jquery -1 . 10 . 2 . min . js & # 039;& gt& lt/script & gt;或者
& lt脚本src = & quot& lt?PHP echo get _ template _ directory _ uri();?& gt/js/jquery/1 . 10 . 2/jquery -1 . 10 . 2 . min . js & quot;& gt& lt/script & gt;2.将文件引入主题functions.php文件,例如
函数my_enqueue_scripts() {if(!Is_admin) {//前台加载的脚本和样式表//移除已注册的jquery脚本WP _ de register _ script(& # 039;jquery & # 039);//注册jquery脚本WP _ Register _ script(& # 039;jquery & # 039,get_template_directory_uri()。'/js/jquery/1 . 10 . 2/jquery -1 . 10 . 2 . min . js & # 039;,假的,& # 039;1.0',假);//提交并加载jquery脚本WP _ enqueue _ script(& # 039;jquery & # 039);} }//在init动作Add _ action(& # 039;init & # 039, '我的入队脚本& # 039;);更多WordPress技术文章,请访问WordPress教程专栏!
评论前必须登录!
注册