我正在将boostrap主题传输到WordPress,并尝试在中添加JavaScript文件functions.php
执行时没有显示错误:
<?php
function regload_javascripts() //need to register first
{
wp_register_script(\'bootstrapjs\', get_template_directory_uri().\'/js/bootstrap.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'bootstrapjs\');
wp_register_script(\'carousel\', get_template_directory_uri().\'/js/carousel.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'carousel\');
wp_register_script(\'custom\', get_template_directory_uri().\'/js/custom.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'custom\');
wp_register_script(\'flexslider\', get_template_directory_uri().\'/js/flexslider.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'flexslider\');
wp_register_script(\'jquery182\', get_template_directory_uri().\'/js/jquery-1.8.2.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'jquery182\');
wp_register_script(\'cslider\', get_template_directory_uri().\'/js/jquery.cslider.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'cslider\');
wp_register_script(\'gmap_min\', get_template_directory_uri().\'/js/jquery.gmap.min.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'gmap_min\');
wp_register_script(\'slider\', get_template_directory_uri().\'/js/slider.js\',array(\'jquery\'),\'1.1\', true);
wp_enqueue_script(\'slider\');
}
add_action (\'wp_enqueue_scripts\', \'regload_javascripts\');
但没有效果。
js文件如下:js files
我的开发人员控制台输出为:
TypeError: $ is undefined carousel.js:3:6079 <anonymous> http://localhost/wordpress/wp-content/themes/bootgotya/js/carousel.js?ver=1:3
TypeError: $ is not a function flexslider.js:14:2 <anonymous> http://localhost/wordpress/wp-content/themes/bootgotya/js/flexslider.js?ver=1:14
Loading failed for the <script> with source “http://localhost/wordpress/js/flexslider.js”. wordpress:590:1
Loading failed for the <script> with source “http://localhost/wordpress/js/carousel.js”. wordpress:591:1
Loading failed for the <script> with source “http://localhost/wordpress/js/jquery.cslider.js”. wordpress:592:1