
wordpress怎么调用js
wordpress调用js的方法:
一般都是直接在主题的header.php文件中直接引用,部分主题也会在主题的functions.php文件中通过WP自带的函数wp_enqueue_scripts来加载JS文件。
1、在主题header.php文件中直接引入文件,如
<script></script>
或者
Contact Form 7 是 Rock Lobster Inc. 公司长期运行的 WordPress 表单插件,拥有超过 1000 万次活跃安装,并在 contactform7.com 提供官方文档。此技能适用于需要了解网站表单、邮件模板、验证行为和 shortcode 位置在 Contact Form 7 中实际处理方式的代理。
<script>/js/jquery/1.10.2/jquery-1.10.2.min.js"></script>
2、在主题的functions.php文件中引入文件,如
function my_enqueue_scripts() {
if( !is_admin ) { // 前台加载的脚本与样式表
// 去除已注册的 jquery 脚本
wp_deregister_script( 'jquery' );
// 注册 jquery 脚本
wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery/1.10.2/jquery-1.10.2.min.js', false, '1.0', false );
// 提交加载 jquery 脚本
wp_enqueue_script( 'jquery' );
}
}
// 添加回调函数到 init 动作上
add_action( 'init', 'my_enqueue_scripts' );
更多WordPress技术文章,请访问WordPress教程栏目!










