正如我在標題中提到的,我的 js 文件遇到了一些問題。我已經測試了 HTML 模板中的腳本并且工作正常,但是當我將它們放入文件中時,functions.php有些腳本無法正常工作。這里是functions.php文件:<?phpfunction 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');}add_action("wp_enqueue_scripts", "load_stylesheets", "add_js", 999);?>
1 回答

函數式編程
TA貢獻1807條經驗 獲得超9個贊
wp_enqueue_scripts
您不能像這樣掛鉤并調用多個函數:
add_action("wp_enqueue_scripts",?"load_stylesheets",?"add_js",?999);
add_action()
接受這四個參數:
$tag
?(字符串)(必需)掛鉤的操作的名稱$function_to_add
。
$function_to_add
(可調用)(必需)您希望調用的函數的名稱。
$priority
?(int)(可選)用于指定與特定操作關聯的函數的執行順序。較低的數字對應于較早的執行,具有相同優先級的函數按照它們添加到操作的順序執行。
默認值:10
$accepted_args
?(int) (可選)函數接受的參數數量。?默認值:1
因此,要添加樣式表和腳本,您必須執行以下操作:
add_action(?'wp_enqueue_scripts',?'load_stylesheets',?999?); add_action(?'wp_enqueue_scripts',?'add_js',?999?);
- 1 回答
- 0 關注
- 175 瀏覽
添加回答
舉報
0/150
提交
取消