【发布时间】:2020-04-11 21:30:27
【问题描述】:
正如我在标题中提到的,我的 js 文件存在一些问题。
我已经测试了 HTML 模板中的脚本并且工作正常,但是当我将它们放入 functions.php 文件时,有些脚本无法正常工作。
这里是functions.php 文件:
<?php
function load_stylesheets(){
/************/
}
function add_js(){
wp_register_script('jquery-min', get_template_directory_uri().'/js/jquery.min.js', array('jquery'), 2, true);
wp_enqueue_script('jquery-min');
wp_register_script('jquery-migrate', get_template_directory_uri().'/js/jquery/jquery-migrate.min.js', array('jquery'), 2, true);
wp_enqueue_script('jquery-migrate');
wp_register_script('popper', get_template_directory_uri().'/js/popper/popper.min.js', array('jquery'), 2, true);
wp_enqueue_script('popper');
wp_register_script('bootstrap', get_template_directory_uri().'/js/bootstrap/js/bootstrap.min.js', array('jquery'), 2, true);
wp_enqueue_script('bootstrap');
wp_register_script('easing', get_template_directory_uri().'/js/easing/easing.min.js', array('jquery'), 2, true);
wp_enqueue_script('easing');
wp_register_script('jquery.waypoints', get_template_directory_uri().'/js/counterup/jquery.waypoints.min.js', array('jquery'), 2, true);
wp_enqueue_script('jquery.waypoints');
wp_register_script('jquery.counterup', get_template_directory_uri().'/js/counterup/jquery.counterup.js', array('jquery'), 2, true);
wp_enqueue_script('jquery.counterup');
wp_register_script('carousel', get_template_directory_uri().'/js/owlcarousel/owl.carousel.min.js', array('jquery'), 2, true);
wp_enqueue_script('carousel');
wp_register_script('lightbox', get_template_directory_uri().'/js/lightbox/js/lightbox.min.js', array('jquery'), 2, true);
wp_enqueue_script('lightbox');
wp_register_script('typed', get_template_directory_uri().'/js/typed/typed.min.js', array('jquery'), 2, true);
wp_enqueue_script('typed');
wp_register_script('contactform', get_template_directory_uri().'/js/contactform.js', array('jquery'), 3, true);
wp_enqueue_script('contactform');
wp_register_script('main', get_template_directory_uri().'/js/main.js', array('jquery'), 3, true);
wp_enqueue_script('main');
}
add_action("wp_enqueue_scripts", "load_stylesheets", "add_js", 999);
?>
提前致谢!
【问题讨论】:
-
您的意思是“没有按应有的方式工作”?他们是否正在加载?
-
日志中没有报错,所以我认为它们加载正确,但是有些功能不起作用,例如流畅的js滚动
-
PD:执行平滑滚动的主脚本在 html-template 版本中运行良好。
标签: javascript php jquery html wordpress