我正在尝试从头开始开发一个 wordpress 主题,但我在使用 function.php
时遇到了一些问题。我想添加额外的 javascript,但问题是它们没有加载“包”,当我检查浏览器中的链接时,我可以看到它们没有像我的样式表那样下载
function humlan_scripts() {
wp_enqueue_style( 'bootstrap.min', get_stylesheet_directory_uri() . '
/css/bootstrap.min.css',false,'3.0.3','all');
wp_enqueue_style( 'prettyPhoto', get_stylesheet_directory_uri() .
'/css/prettyPhoto.css',false,'1.1','all');
wp_enqueue_style( 'font-awesome.min', get_stylesheet_directory_uri() .
'/css/font-awesome.min.css',false,'1.1','all');
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() .
'/css/animate.css',false,'1.1','all');
wp_enqueue_style( 'main', get_stylesheet_directory_uri() .
'/css/main.css',false,'1.1','all');
wp_enqueue_style( 'responsive', get_stylesheet_directory_uri() .
'/css/responsive.css',false,'1.1','all');
wp_enqueue_script( 'jquery', get_stylesheet_directory_uri() .
'/js/jquery.js', array(), '20151215', true );
wp_enqueue_script( 'bootstrap.min', get_stylesheet_directory_uri() .
'/js/bootstrap.min.js', array(), '20151215', true );
wp_enqueue_script( 'smoothscroll', get_stylesheet_directory_uri() .
'/js/smoothscroll.js', array(), '20151215', true );
wp_enqueue_script( 'jquery.isotope.min', get_stylesheet_directory_uri() . '
/js/jquery.isotope.min.js', array(), '20151215', true );
wp_enqueue_script( 'jquery.prettyPhoto', get_stylesheet_directory_uri() .
'/js/jquery.prettyPhoto.js', array(), '20151215', true );
wp_enqueue_script( 'jquery.parallax', get_stylesheet_directory_uri() .
'/js/jquery.parallax.js', array(), '20151215', true );
wp_enqueue_script( 'main', get_stylesheet_directory_uri() . '/js/main.js',
array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'humlan_scripts' );
问题是我该如何解决?
谢谢!
最佳答案
wp_enqueue_style 和 wp_enqueue_script 函数总是需要排队文件的 URL。现在,当您使用 get_stylesheet_directory_uri() 时,它会尝试从主题文件夹中的 css 文件夹加载它。所以请检查文件是否存在于该位置。或者您可以使用类似“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”的 URL,这样文件将从 url 加载。
注意:使用 get_template_directory_uri() 而不是 get_stylesheet_directory_uri()
希望对你有帮助
关于javascript - 从头开始的 wordpress 主题不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45090598/